Created
August 26, 2013 19:56
-
-
Save chilts/6345907 to your computer and use it in GitHub Desktop.
Gist to compare two ways of creating the string for flake (https://npmjs.org/package/flake) IDs. I suspect the construction of the array far outweighs the construction of the string.
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 t1, t2, t3; | |
var i; | |
const TOP = 1000000000; | |
var tsHex = '013c798f75ad'; | |
var counterHex = '0000'; | |
var pidHex = '1154'; | |
var macHex = '984be1b8b104'; | |
t1 = Date.now(); | |
for (i=0; i< TOP; i++) { | |
tsHex + '-' + counterHex + '-' + pidHex + '-' + macHex; | |
} | |
t2 = Date.now(); | |
for (i=0; i< TOP; i++) { | |
[tsHex, counterHex, pidHex, macHex].join('-'); | |
} | |
t3 = Date.now(); | |
// about 85ms | |
console.log('1=' + (t2-t1) + 'ms'); | |
// about 53000ms (53s)!! | |
console.log('2=' + (t3-t2) + 'ms'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment