benchmark.js test page

JavaScript performance comparison

Test case created by Mathias and last updated

Info

This is just a test document for benchmark.js.

Preparation code

<div id="foo">Foo!</div>
<script>
 var arr = [1, 5, 4, 2, 3],
     i = 1;
</script>

Preparation code output

Foo!

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

Testing in
Test Ops/sec
Sort ascending
var x = arr;
x.sort(function(a, b) {
  return a - b;
});
Sort descending
var x = arr;
x.sort(function(a, b) {
  return b - a;
});
Don’t sort at all
var foo, x = i;
while (x--) {
  foo = Array(x).join("-");
}
Error
arr.foo(); // unknown method
      
Just another unrelated test
var x = arr,
    y = ~~(Math.random() * 100);
while (y--) {
  if (arr[y]) {
    arr[y];
  } else {
    // Boohoo
  }
}

Results

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