branch-prediction

JavaScript performance comparison

Revision 5 of this test case created by Alejandro

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var arraySize = 32768;
    var array = [];
    var arraySorted = [];
   
    for (var i = 0; i < arraySize; ++i) {
      var value = Math.floor(Math.random() * 256);
      array[i] = value;
      arraySorted[i] = value;
    }
   
    var sum = 0;
   
    arraySorted.sort(function (a, b) {
      return a - b;
    })
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Not Sorted Array
for (var j = 0; j < arraySize; ++j) {
  if (array[j] < 128) {
    sum += array[j];
  }
}
 
pending…
Sorted Array
for (var j = 0; j < arraySize; ++j) {
  if (arraySorted[j] < 128) {
    sum += arraySorted[j];
  }
}
 
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Comment form temporarily disabled.

Add a comment