Skip to content

Instantly share code, notes, and snippets.

@chjj chjj/joinvconcat.js
Created May 7, 2011

Embed
What would you like to do?
join v concat
(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
You can’t perform that action at this time.