arithmetic vs compare
JavaScript performance comparison
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.
| Test | Ops/sec | |
|---|---|---|
+ |
|
pending… |
< |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments