string concat vs array join (v43)

Revision 43 of this benchmark created by theoutlander on


Setup

var words = ['this', 'is', 'a', 'test'];
  
  var text = words[0];
  
  var a = [words[0]];
  var b = [];
  var c = [];
  var i;
  
  var text2;

Test runner

Ready to run.

Testing in
TestOps/sec
Concat
for(i = 1; i < 10000; ++i)
{
    text += ' ' + words[i & 3] + Math.random();
}

text2 = text;
ready
Join
for(i = 1; i < 10000; ++i)
{
    a.push(' ',words[i & 3],Math.random());
}

text2 = a.join('');
ready
Join without push()
for(i = 1; i < 10000; ++i)
{
    a[i] = ' ' + words[i & 3] + Math.random();
}

text2 = a.join('');
ready
Join without space concat
for(i = 1; i < 10000; ++i)
{
    a[i] = words[i & 3] + Math.random();
}

text2 = a.join(' ');
ready
Join without concat
for(i = 1; i < 20000; ++i)
{
    a[i] = words[i & 3]
    a[++i] = Math.random();
}

text2 = a.join(' ');
ready
Concat two words
text2 = 123 + "px;
ready
Join two words
c[0] = 123;
c[1] = "px";

text2 = c.join(' ');
ready

Revisions

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