Created
June 30, 2015 15:52
-
-
Save miguelcnf/dedd55148fa0baf6af33 to your computer and use it in GitHub Desktop.
node util.format performance test
This file contains hidden or 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
#!/usr/bin/env node | |
var fs = require('fs'); | |
fs.readFile('urandomStrings', 'utf8', function (err,data) { | |
if (err) { | |
return console.log(err); | |
} else { | |
console.time('concat'); | |
var string = ''; | |
string = data + 'foo'; | |
console.timeEnd('concat'); | |
} | |
}); |
This file contains hidden or 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
#!/usr/bin/env node | |
console.time('concat'); | |
var string = ''; | |
for (var i = 0; i < 10000; i++) { | |
string = 'bar' + 'foo'; | |
} | |
console.timeEnd('concat'); |
This file contains hidden or 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
#!/usr/bin/env node | |
console.time('concat'); | |
var string = ''; | |
string = 'bar' + 'foo'; | |
console.timeEnd('concat'); |
This file contains hidden or 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
[miguelfonseca@miguel-mbp ~]$ node plusMultipleTimes.js | |
concat: 0ms | |
[miguelfonseca@miguel-mbp ~]$ node utilMultipleTimes.js | |
concat: 18ms | |
[miguelfonseca@miguel-mbp ~]$ node plusLargeData.js | |
concat: 0ms | |
[miguelfonseca@miguel-mbp ~]$ node utilLargeData.js | |
concat: 3ms | |
[miguelfonseca@miguel-mbp ~]$ node plusSimple.js | |
concat: 0ms | |
[miguelfonseca@miguel-mbp ~]$ node utilSimple.js | |
concat: 0ms |
This file contains hidden or 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
#!/usr/bin/env node | |
var fs = require('fs'); | |
var util = require('util'); | |
fs.readFile('urandomStrings', 'utf8', function (err,data) { | |
if (err) { | |
return console.log(err); | |
} else { | |
console.time('concat'); | |
var string = ''; | |
string = util.format('%s%s', data, 'foo'); | |
console.timeEnd('concat'); | |
} | |
}); |
This file contains hidden or 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
#!/usr/bin/env node | |
var util = require('util'); | |
console.time('concat'); | |
var string = ''; | |
for (var i = 0; i < 10000; i++) { | |
string = util.format('%s%s', 'bar', 'foo'); | |
} | |
console.timeEnd('concat'); |
This file contains hidden or 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
#!/usr/bin/env node | |
var util = require('util'); | |
console.time('concat'); | |
var string = ''; | |
string = util.format('%s%s', 'bar', 'foo'); | |
console.timeEnd('concat'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment