Created
August 31, 2015 11:10
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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