string concat vs array join (v9)

Revision 9 of this benchmark created on


Setup

var words = ['this', 'is', 'a', 'test'];
  
  var counter = 0;
  var length = 10000;
  var i;
  
  var re = /z/;
  var result;

Test runner

Ready to run.

Testing in
TestOps/sec
Concat
var text = words[0];
for(i = 1; i < length; ++i)
{
    text += ' ' + words[i & 3] + (counter++);
}

result = re.test(text);
ready
Join
var a = [words[0]];
for(i = 1; i < length; ++i)
{
    a.push(' ', words[i & 3], counter++);
}

result = re.test(a.join(''));
ready
Join without push()
var a = [words[0]];
for(i = 1; i < length; ++i)
{
    a[i] = ' ' + words[i & 3] + (counter++);
}

result = re.test(a.join(''));
ready

Revisions

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