string concat vs array join

JavaScript performance comparison

Revision 74 of this test case created by Evan Sharp

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var words = ['this', 'is', 'a', 'test'];
  
  var counter = 0;
  var length = 1000;
  var i;
  
  var re = /z/;
  var result;

};
</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
text += string templating
var text = '';
for(i = 0; i < length; ++i)
{
    text += `${words[i & 3]}${counter++};
}

result = re.test(text);
pending…
text = ${text} string templating
var text = '';
for(i = 0; i < length; ++i)
{
    text = `${text} ${words[i & 3]}${counter++};
}

result = re.test(text);
pending…

Revisions

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

0 Comments