remove-sign-from-number

JavaScript performance comparison

Revision 3 of this test case created

Preparation code

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

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;
pending…
if-then -n
if(n < 0) n = -n;
pending…
Math.abs
n = Math.abs(n)
pending…
logic *=
(n < 0) && (n *= -1)
pending…
logic -n
(n < 0) && (n = -n)
pending…
bit-if
if (n < 0) n = ~n+1
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