remove-sign-from-number

JavaScript performance comparison

Revision 5 of this test case created

Info

Removed bitwise comparisons, unnecessary parentheses

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var n = 5*Math.random() - 10;
    var abs = Math.abs;
};

Benchmark.prototype.teardown = function() {
    if(n < 0) throw "BadTestResult"
};
</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
if-then *=
if(n < 0) n *= -1;
n *= Math.random() + 0.5;
pending…
if-then -n
if(n < 0) n = -n;
n *= Math.random() + 0.5;
pending…
Math.abs
n = abs(n);
n *= Math.random() + 0.5;
pending…
logic *=
n < 0 && (n *= -1);
n *= Math.random() + 0.5;
pending…
logic or
n > 0 || (n *= -1);
n *= Math.random() + 0.5;
pending…
logic -n
n < 0 && (n = -n);
n *= Math.random() + 0.5;
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