Created
January 8, 2023 15:14
-
-
Save H4ad/38fc55fae31b4f0b77660094bdb17fbe to your computer and use it in GitHub Desktop.
Ogma Benchmark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// to run this file, install: npm i --save benchmark pino @ogma/logger @nestjs/common | |
// and then just run with: npx ts-node benchmark.ts | |
import { Logger } from '@nestjs/common'; | |
import { Ogma } from '@ogma/logger'; | |
import pino from 'pino'; | |
import * as Benchmark from 'benchmark'; | |
const suite = new Benchmark.Suite(); | |
const nestjsLogger = new Logger(); | |
const ogmaLogger = new Ogma(); | |
const pinoLogger = pino(); | |
suite.add('NestJS Logger', function () { | |
nestjsLogger.log('Hello World!'); | |
}); | |
suite.add('Ogma', function () { | |
ogmaLogger.info('Hello World!'); | |
}); | |
suite.add('Pino', function () { | |
pinoLogger.info('Hello World!'); | |
}); | |
suite.add('console.log', function () { | |
console.log('Hello World!'); | |
}); | |
suite.add('process.stdout', function () { | |
process.stdout.write('Hello World!\n'); | |
}); | |
const results = []; | |
suite | |
// add listeners | |
.on('cycle', function (event) { | |
results.push(String(event.target)); | |
}) | |
.on('complete', function () { | |
results.forEach(console.log); | |
console.log('Fastest is ' + this.filter('fastest').map('name')); | |
}) | |
.run({ | |
async: true, | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this file I use to get the profiler information | |
// to run this file, compile to JavaScript first, | |
// then you run: node --prof dist/ogma-log.stress.js | |
// this will generate a file called: isolate-0xnnnnnnnnnnnn-v8.log | |
// to be able to read the information inside this file, run: | |
// node --prof-process isolate-0xnnnnnnnnnnnn-v8.log > processed.txt | |
import { Ogma } from '@ogma/logger'; | |
const ogmaLogger = new Ogma(); | |
for (let i = 0; i < 1e6; i++) | |
ogmaLogger.log('Hello World!'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment