String concatenation comparison (v60)

Revision 60 of this benchmark created on


Setup

var words = ['Longer fragments', 'improve the test', 'because it may tickle', 'buffer reallocation', 'arbitrary content', 'that creates', 'a lengthier', 'test case'];
  
  var length = 1024, length2 = 2048;

Test runner

Ready to run.

Testing in
TestOps/sec
Concat x += ''
var text = '';
for(var i = 0; i < length; ++i) {
    text += words[i & 3] + words[i & 7];
}
console.log(text.charAt(length));
ready
Concat x += '', separate substrings
var text = '';
for(var i = 0; i < length; ++i) {
    text += words[i & 3]
    text += words[i & 7]
}
console.log(text.charAt(length));
ready
Concat x = x + ''
var text = '';
for(var i = 0; i < length; ++i) {
    text = text + words[i & 3] + words[i & 7];
}
console.log(text.charAt(length));
ready
Concat x = x + '', separate substrings
var text = '';
for(var i = 0; i < length; ++i) {
    text = text + words[i & 3];
    text = text + words[i & 7];
}
console.log(text.charAt(length));
ready
String.prototype.concat
var text = '';
for(var i = 0; i < length; ++i) {
    text = text.concat(words[i & 3], words[i & 7]);
}
console.log(text.charAt(length));
ready
String.prototype.concat, +'d substring
var text = '';
for(var i = 0; i < length; ++i) {
    text = text.concat(words[i & 3] + words[i & 7]);
}
console.log(text.charAt(length));
ready
String.prototype.concat, separate substrings
var text = '';
for(var i = 0; i < length; ++i) {
    text = text.concat(words[i & 3]);
    text = text.concat(words[i & 7]);
}
console.log(text.charAt(length));
ready
Array.push, multiple args
var a = [];
for(var i = 0; i < length; ++i) {
    a.push(words[i & 3], words[i & 7]);
}
console.log(a.join('').charAt(length));
ready
Array.push, multiple calls
var a = [];
for(var i = 0; i < length; ++i) {
    a.push(words[i & 3])
    a.push(words[i & 7])
}
console.log(a.join('').charAt(length));
ready
Array.push, +'d arg
var a = [];
for(var i = 0; i < length; ++i) {
    a.push(words[i & 3] + words[i & 7]);
}
console.log(a.join('').charAt(length));
ready
Array assignment
var a = [];
for(var i = 0; i < length2; ++i) {
    a[i] = words[i & 3];
    a[++i] = words[i & 7];
}
console.log(a.join('').charAt(length));
ready
Array assignment, +'d value
var a = [];
for(var i = 0; i < length; ++i) {
    a[i] = words[i & 3] + words[i & 7];
}
console.log(a.join('').charAt(length));
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.