-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.js
124 lines (110 loc) · 2.73 KB
/
benchmark.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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()