Created
May 7, 2011 05:29
join v concat
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
(function() { | |
var start = Date.now(); | |
var i = 1000000; | |
while (i--) { | |
var str = ''; | |
str += 'a'; | |
str += 'a'; | |
str += 'a'; | |
str += 'a'; | |
str += 'a'; | |
str += 'a'; | |
str += 'a'; | |
//str += 'a'; | |
//str += 'a'; | |
//str += 'a'; | |
} | |
console.log('CONCAT:', Date.now() - start); | |
})(); | |
(function() { | |
var start = Date.now(); | |
var i = 1000000; | |
while (i--) { | |
var str = []; | |
str.push('a'); | |
str.push('a'); | |
str.push('a'); | |
str.push('a'); | |
str.push('a'); | |
str.push('a'); | |
str.push('a'); | |
//str.push('a'); | |
//str.push('a'); | |
//str.push('a'); | |
str.join(''); | |
} | |
console.log('JOIN:', Date.now() - start); | |
})(); | |
(function() { | |
var start = Date.now(); | |
var i = 1000000; | |
while (i--) { | |
[ | |
'a', | |
'a', | |
'a', | |
'a', | |
'a', | |
'a', | |
'a' | |
].join(''); | |
} | |
console.log('JOIN LITERAL:', Date.now() - start); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment