String Concatenation versus Array.join (v2)

Revision 2 of this benchmark created by electricessence on


Setup

var resultConcat = "";
  var resultArray = [];
  var max = 10000;

Teardown



            // just to be sure memory isn't an issue.
  resultConcat = "";
  resultArray = [];
        
  

Test runner

Ready to run.

Testing in
TestOps/sec
resultConcat += i + "";
for(var i=0;i<max;i++)
{
  resultConcat += i + "";
}
// We arrive here with the actual result.
ready
resultArray[i] = i + ""
for(var i=0;i<max;i++)
{
  resultArray[i] = i + "";
}
resultConcat = resultArray.join();
// We arrive here with the actual result.
ready
var i2 = i * 2; resultArray[i2] = i; resultArray[i2+1] = ""; ""
for(var i=0;i<max;i++)
{
  var i2 = i * 2;
  resultArray[i2] = i;
  resultArray[i2 + 1] = "";
}
resultConcat = resultArray.join();
// We arrive here with the actual result.
ready
var i2 = resultArray.length; resultArray[i2] = i; resultArray[i2+1] = ""; ""
for(var i=0;i<max;i++)
{
  var i2 = resultArray.length;
  resultArray[i2] = i;
  resultArray[i2 + 1] = "";
}
resultConcat = resultArray.join();
// We arrive here with the actual result.
ready
resultConcat.push(i + "");
for(var i=0;i<max;i++)
{
  resultArray.push(i + "");
}
resultConcat = resultArray.join();
// We arrive here with the actual result.
ready
resultConcat.push(i, "");
for(var i=0;i<max;i++)
{
  resultArray.push(i, "");
}
resultConcat = resultArray.join();
// We arrive here with the actual result.
ready

Revisions

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

  • Revision 2: published by electricessence on