TPMi_Math_Round

JavaScript performance comparison

Test case created by TPMi

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var a = 0;
    var b = 0.1;
    var c = 0.49;
    var d = 0.5;
    var e = 0.51;
    var f = 0.9;
    var g = 1;
    var mathround = Math.round;
    var bitshiftmathround1 = function (x) { return ((x + 0.5)<<1)>>1 };
    var bitshiftmathround2 = function (x) { return ~~(x + 0.5) };
};
</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
Math.round
//mathround(a);
mathround(b);
mathround(c);
mathround(d);
mathround(e);
mathround(f);
//mathround(g);
 
pending…
Bits round
//bitshiftmathround1(a);
bitshiftmathround1(b);
bitshiftmathround1(c);
bitshiftmathround1(d);
bitshiftmathround1(e);
bitshiftmathround1(f);
//bitshiftmathround1(g);
 
pending…
Bits round 2
//bitshiftmathround2(a);
bitshiftmathround2(b);
bitshiftmathround2(c);
bitshiftmathround2(d);
bitshiftmathround2(e);
bitshiftmathround2(f);
//bitshiftmathround2(g);
 
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