-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from stencila/perf
BREAKING CHANGE: Mostly internal performance improvements but given the scale of changes labeling as a breaking change to trigger a major release.
- Loading branch information
Showing
8 changed files
with
275 additions
and
119 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/** | ||
* Benchmarks comparing the speed of Logga to other Node.js logging frameworks | ||
* | ||
* First install the benchmark and logging libraries | ||
* | ||
* ```sh | ||
* npm install --no-save benchmark bole bunyan log4js loglevel pino winston | ||
* ``` | ||
* | ||
* Then to rebuild Logga and run the benchmarks, | ||
* | ||
* ```sh | ||
* npm run bench | ||
* ``` | ||
* | ||
* All frameworks configured to log errors to `stderr`. | ||
* Build Logga if necessary before running benchmarks. | ||
* Best run by redireting `stderr` to `/dev/null` e.g. | ||
* | ||
*/ | ||
|
||
const Benchmark = require('benchmark') | ||
|
||
// Import each of the libraries used | ||
|
||
const bole = require('bole') | ||
const bunyan = require('bunyan') | ||
const log4js = require('log4js') | ||
const logga = require('.') | ||
const loglevel = require('loglevel') | ||
const pino = require('pino') | ||
const winston = require('winston') | ||
|
||
// Instantiate loggers for each library | ||
|
||
const boleLogger = bole('bench') | ||
bole | ||
.output({ | ||
level: 'error', | ||
stream: process.stderr, | ||
}) | ||
.setFastTime(true) | ||
|
||
const bunyanLogger = bunyan.createLogger({ | ||
name: 'bench', | ||
streams: [ | ||
{ | ||
level: 'error', | ||
stream: process.stderr, | ||
}, | ||
], | ||
}) | ||
|
||
var log4jsLogger = log4js.getLogger() | ||
log4jsLogger.level = 'error' | ||
log4js.configure({ | ||
appenders: { err: { type: 'stderr' } }, | ||
categories: { default: { appenders: ['err'], level: 'ERROR' } }, | ||
}) | ||
|
||
const loggaLogger = logga.getLogger('bench') | ||
logga.replaceHandlers((entry) => { | ||
logga.defaultHandler(entry, { fastTime: true, exitOnError: false }) | ||
}) | ||
|
||
const loglevelLogger = loglevel.getLogger('bench') | ||
loglevelLogger.setLevel('error') | ||
|
||
const pinoLogger = pino(process.stderr, { name: 'bench' }) | ||
|
||
const winstonLogger = winston.createLogger({ | ||
transports: [ | ||
new winston.transports.Stream({ | ||
stream: process.stderr, | ||
}), | ||
], | ||
}) | ||
|
||
// Run the benchmark suites! | ||
|
||
// A more precise benchmark for comparing performance | ||
// across changes in code | ||
new Benchmark.Suite() | ||
.add('logga', { | ||
minSamples: 500, | ||
fn: function () { | ||
loggaLogger.error('derp') | ||
}, | ||
}) | ||
.on('cycle', function (event) { | ||
console.log(String(event.target)) | ||
}) | ||
.run() | ||
|
||
// For comparison with other libraries | ||
new Benchmark.Suite() | ||
.add('bole', function () { | ||
boleLogger.error('derp') | ||
}) | ||
.add('bunyan', function () { | ||
bunyanLogger.error('derp') | ||
}) | ||
.add('logga', function () { | ||
loggaLogger.error('derp') | ||
}) | ||
.add('log4js', function () { | ||
log4jsLogger.error('derp') | ||
}) | ||
.add('loglevel', function () { | ||
loglevelLogger.error('derp') | ||
}) | ||
.add('pino', function () { | ||
pinoLogger.error('derp') | ||
}) | ||
.add('winston', function () { | ||
winstonLogger.error('derp') | ||
}) | ||
.on('cycle', function (event) { | ||
console.log(String(event.target)) | ||
}) | ||
.on('complete', function () { | ||
console.log('Fastest is ' + this.filter('fastest').map('name')) | ||
}) | ||
.run() |
This file contains 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 contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { LogHandler } from './index' | ||
|
||
declare global { | ||
namespace NodeJS { | ||
interface Global { | ||
_logga?: LogHandler[] | ||
} | ||
} | ||
|
||
interface Window { | ||
_logga?: LogHandler[] | ||
} | ||
} |
This file contains 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
Oops, something went wrong.