Array vs AppendText

JavaScript performance comparison

Test case created by Patrick

Info

Using a string or array to see if all 16 cases have been met.

Preparation code

<div id="output"></div>
<script>
Benchmark.prototype.setup = function() {
    var output = document.getElementById('output');
};
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Using an array
var blankArray = [];

for (x = 0; x < 16; x++) {

  blankArray.push("s" + x);
}

output.innerHTML = blankArray.toString;
pending…
Using a string
var blankString = "";

for (x = 0; x < 16; x++) {

  if (x == 15) {
    blankString += "s" + x;
  } else {
    blankString += "s" + x + ",";
  }

}

output.innerHTML = blankString;
pending…

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

Compare results of other browsers

0 comments

Add a comment