Summing Ordered vs Unordered

JavaScript performance comparison

Test case created by imma

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var u = [],
      o = [],
      size = 10000;
   
    // set up two lists
    for (var c = 0; c < size; c++) {
      u[c] = Math.random();
      o[c] = u[c];
    }
   
    // sort one of them
    o.sort();
};
</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
Sum >0.5 in Ordered
var sum = 0;
for (var c = 0; c < size; c++) {
  if (o[c] > 0.5) sum += o[c];
}
pending…
Sum >0.5 in Unordered
var sum = 0;
for (var c = 0; c < size; c++) {
  if (u[c] > 0.5) sum += u[c];
}
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