2012-02-07 05:34:04 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
/*
|
|
|
|
* Time logging with/without a try/catch-guard on the JSON.stringify.
|
|
|
|
*/
|
|
|
|
|
2012-02-10 08:14:33 +00:00
|
|
|
console.log('Time try/catch-guard on JSON.stringify:');
|
2012-02-07 05:34:04 +00:00
|
|
|
|
|
|
|
var ben = require('ben'); // npm install ben
|
2014-11-18 06:49:38 +00:00
|
|
|
var bunyan = require('../lib/bunyan');
|
2012-02-07 05:34:04 +00:00
|
|
|
|
2014-11-18 06:49:38 +00:00
|
|
|
function Collector() {}
|
|
|
|
Collector.prototype.write = function (s) {};
|
2012-02-07 05:34:04 +00:00
|
|
|
|
2014-11-18 06:49:38 +00:00
|
|
|
var log = bunyan.createLogger({
|
2013-03-29 00:42:32 +00:00
|
|
|
name: 'timeguard',
|
2014-11-18 06:49:38 +00:00
|
|
|
stream: new Collector()
|
2012-02-07 05:34:04 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
var ms = ben(1e5, function () {
|
2013-03-29 00:42:32 +00:00
|
|
|
log.info('hi');
|
2012-02-07 05:34:04 +00:00
|
|
|
});
|
|
|
|
console.log(' - log.info: %dms per iteration', ms);
|
2014-11-18 06:49:38 +00:00
|
|
|
|
|
|
|
console.log('\nNow you need to manually change `Logger.prototype._emit` in\n'
|
|
|
|
+ '"../lib/bunyan.js" to (not) have a try/catch around `JSON.stringify`.\n'
|
|
|
|
+ 'Then re-run this a few times to compare speed.');
|