String concatenation comparison

JavaScript performance comparison

Revision 60 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  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;

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Concat x += ''
var text = '';
for(var i = 0; i < length; ++i) {
    text += words[i & 3] + words[i & 7];
}
console.log(text.charAt(length));
pending…
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));
pending…
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));
pending…
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));
pending…
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));
pending…
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));
pending…
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));
pending…
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));
pending…
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));
pending…
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));
pending…
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));
pending…
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));
pending…

Compare results of other browsers

Revisions

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

0 Comments