arithmetic vs compare

JavaScript performance comparison

Test case created

Preparation code

<script>
function Range(a,b,c,d){
this.s={row:a,column:b}
this.e={row:c,column:d}
}
var rl = []
for (var i= 10000;i--;) {
rl.push(new Range(
  Math.round(Math.random()*1000),
  Math.round(Math.random()*1000),
  Math.round(Math.random()*1000),
  Math.round(Math.random()*1000)
))
}

comparePoints1 = function(p1, p2) {
    return p1.row - p2.row || p1.column - p2.column;
};
comparePoints2 = function(p1, p2) {
    if (p1.row < p2.row)
       return -1
     if (p1.row > p2.row)
       return 1
    if (p1.column < p2.column)
       return -1;
    if (p1.column > p2.column)
       return 1
    return 0
};

</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
+
rl.forEach(function(x){comparePoints1(x.s,x.e)>0})
pending…
<
rl.forEach(function(x){comparePoints2(x.s,x.e)===1})
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