Skip to content

Instantly share code, notes, and snippets.

@dhruvbird
Created June 21, 2012 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhruvbird/2966346 to your computer and use it in GitHub Desktop.
Save dhruvbird/2966346 to your computer and use it in GitHub Desktop.
Performance test for new Error() on node.js
var path = require('path');
var filename = path.basename(path.normalize(__filename))
// Install deps:
// $> npm install log4js
// $> npm install node-lumberjack
//
// Run as:
// $> time node stress.js > /dev/null
function stress_log(log) {
var i;
for (i = 0; i < 100000; ++i) {
log.info("Counter Value = %s", i);
}
}
function test_node_lumberjack() {
var lumberjack = require('node-lumberjack')
var log = lumberjack.getLogger(filename, 'info');
stress_log(log);
}
function test_log4js() {
var log4js = require("log4js");
log4js.configure({
doNotReplaceConsole: true
});
var appender = log4js.consoleAppender(log4js.basicLayout);
log4js.clearAppenders();
log4js.addAppender(appender);
log4js.setGlobalLogLevel("INFO");
var log = log4js.getLogger(filename);
stress_log(log);
}
// Comment out one or the other to test the running time.
test_node_lumberjack();
// test_log4js();
// I see 15sec for node-lumberjack and 3sec for log4js which is a 5x difference.
// If I remove the new Error().stack bit from node-lumberjack, the running time is 3sec (similar to log4js)
// So, the overhead of doing a new Error() is pretty high.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment