sorted-loop

JavaScript performance comparison

Revision 2 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var len = 10000;
    var data = [];
    var sorted = [];
    for (var x = 0; x < len; x++) {
        var r = Math.floor(Math.random() * 256)
        data.push(r);
        sorted.push(r);
    }
    sorted.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
non-sorted + cond
var sum = 0;
for (var i = 0; i < len; i++) {
    if (data[i] >= 128) {
        sum += data[i];
    }
}
return sum;
 
pending…
sorted + cond
var sum = 0;
for (var i = 0; i < len; i++) {
    if (sorted[i] >= 128) {
        sum += sorted[i];
    }
}
return sum;
 
pending…
non-sorted + bitwise
var sum = 0;
for (var i = 0; i < len; i++) {
    var t = (data[i] - 128) >> 31;
    sum += ~t & data[i];
}
return sum;
 
pending…
sorted + bitwise
var sum = 0;
for (var i = 0; i < len; i++) {
    var t = (sorted[i] - 128) >> 31;
    sum += ~t & sorted[i];
}
return sum;
 
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

Add a comment