Skip to content

Instantly share code, notes, and snippets.

@edsykes
Created August 31, 2015 11:10
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 edsykes/6ded94fdb5f2abe73b1e to your computer and use it in GitHub Desktop.
Save edsykes/6ded94fdb5f2abe73b1e to your computer and use it in GitHub Desktop.
speed comparison of util.format vs array.join vs string concatenation in node version 0.12.2
var util = require('util');
var winston = require('winston');
for (var runs = 0; runs < 100; runs++) {
winston.profile('utilformat');
var output = "";
for (var i = 0; i < 10000; i++) {
output = util.format('%s: %d: %d: %d: %s: %s', 'testing', i, i, i, 'another', 'once more');
}
winston.profile('utilformat');
winston.profile('join');
for (var i = 0; i < 10000; i++) {
output = ['testing', i, i, i, 'another', 'once more'].join(': ');
}
winston.profile('join');
winston.profile('stringcat');
for (var i = 0; i < 10000; i++) {
output = 'testing: ' + i +': ' + i + ': ' + i + ': another' + ': once more';
}
winston.profile('stringcat');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment