2012-02-05 05:42:47 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
/*
|
|
|
|
* Time `log.child(...)`.
|
|
|
|
*
|
|
|
|
* Getting 0.011ms on my Mac. For about 1000 req/s that means that the
|
|
|
|
* `log.child` would be about 1% of the time handling that request.
|
|
|
|
* Could do better. I.e. consider a hackish fast path.
|
|
|
|
*
|
|
|
|
* ...
|
|
|
|
*
|
|
|
|
* Added: `log.fastchild({...}, true)`. Use the `true` to assert that
|
|
|
|
* the given options are just new fields (and no serializers).
|
|
|
|
* Result: Another order of magnitude.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var ben = require('ben'); // npm install ben
|
|
|
|
var Logger = require('../lib/bunyan');
|
|
|
|
|
|
|
|
var log = new Logger({
|
2013-03-29 00:42:32 +00:00
|
|
|
name: 'svc',
|
|
|
|
streams: [
|
|
|
|
{
|
|
|
|
path: __dirname + '/timechild.log'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
stream: process.stdout
|
|
|
|
}
|
|
|
|
],
|
|
|
|
serializers: {
|
|
|
|
err: Logger.stdSerializers.err
|
2012-02-05 05:42:47 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-02-10 08:14:33 +00:00
|
|
|
console.log('Time `log.child`:');
|
2012-02-05 05:42:47 +00:00
|
|
|
|
|
|
|
var ms = ben(1e5, function () {
|
2013-03-29 00:42:32 +00:00
|
|
|
var child = log.child();
|
2012-02-05 05:42:47 +00:00
|
|
|
});
|
|
|
|
console.log(' - adding no fields: %dms per iteration', ms);
|
|
|
|
|
|
|
|
var ms = ben(1e5, function () {
|
2013-03-29 00:42:32 +00:00
|
|
|
var child = log.child({a:1});
|
2012-02-05 05:42:47 +00:00
|
|
|
});
|
|
|
|
console.log(' - adding one field: %dms per iteration', ms);
|
|
|
|
|
|
|
|
var ms = ben(1e5, function () {
|
2013-03-29 00:42:32 +00:00
|
|
|
var child = log.child({a:1, b:2});
|
2012-02-05 05:42:47 +00:00
|
|
|
});
|
|
|
|
console.log(' - adding two fields: %dms per iteration', ms);
|
|
|
|
|
|
|
|
function fooSerializer(obj) {
|
2013-03-29 00:42:32 +00:00
|
|
|
return {bar: obj.bar};
|
2012-02-05 05:42:47 +00:00
|
|
|
}
|
|
|
|
var ms = ben(1e5, function () {
|
2013-03-29 00:42:32 +00:00
|
|
|
var child = log.child({
|
|
|
|
a: 1,
|
|
|
|
serializers: {foo: fooSerializer}
|
|
|
|
});
|
2012-02-05 05:42:47 +00:00
|
|
|
});
|
|
|
|
console.log(' - adding serializer and one field: %dms per iteration', ms);
|
|
|
|
|
|
|
|
var ms = ben(1e5, function () {
|
2013-03-29 00:42:32 +00:00
|
|
|
var child = log.child({
|
|
|
|
a: 1,
|
|
|
|
streams: [ {stream: process.stderr} ]
|
|
|
|
});
|
2012-02-05 05:42:47 +00:00
|
|
|
});
|
2012-02-10 08:14:33 +00:00
|
|
|
console.log(' - adding a (stderr) stream and one field: %dms per iteration',
|
2013-03-29 00:42:32 +00:00
|
|
|
ms);
|
2012-02-05 05:42:47 +00:00
|
|
|
|
|
|
|
var ms = ben(1e6, function () {
|
2013-03-29 00:42:32 +00:00
|
|
|
var child = log.child({}, true);
|
2012-02-05 05:42:47 +00:00
|
|
|
});
|
|
|
|
console.log(' - [fast] adding no fields: %dms per iteration', ms);
|
|
|
|
|
|
|
|
var ms = ben(1e6, function () {
|
2013-03-29 00:42:32 +00:00
|
|
|
var child = log.child({a:1}, true);
|
2012-02-05 05:42:47 +00:00
|
|
|
});
|
|
|
|
console.log(' - [fast] adding one field: %dms per iteration', ms);
|
|
|
|
|
|
|
|
var ms = ben(1e6, function () {
|
2013-03-29 00:42:32 +00:00
|
|
|
var child = log.child({a:1, b:2}, true);
|
2012-02-05 05:42:47 +00:00
|
|
|
});
|
|
|
|
console.log(' - [fast] adding two fields: %dms per iteration', ms);
|