Short String Concatenation

Benchmark created by Travis Johnson on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<ul id="test-output">
</ul>
<script>
  var arr = [],
      $testOutput = $("#test-output");
  
  for (var i = 0; i < 100; i++) {
    arr.push({
      firstName: "Travis" + i,
      lastName: "Johnson" + i
    });
  }
  
  $testOutput.hide();
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
String Concat
for (var j = 0; j < arr.length; j++) {
  $testOutput.append($("<li>" + arr[j].lastName + ", " + arr[j].firstName + "</li>"));
}
ready
Array.Join
for (var j = 0; j < arr.length; j++) {
  $testOutput.append($(["<li>", arr[j].lastName, ", ", arr[j].firstName, "</li>"].join("")));
}
ready

Revisions

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

  • Revision 1: published by Travis Johnson on