Math.abs vs custom abs function

JavaScript performance comparison

Revision 3 of this test case created by PetkaAntonov

Preparation code

<script>
var int1 = -12345;
var int2 = 12345;
var float1 = -12345.67;
var float2 = 12345.67;
var abs = Math.abs;
</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.abs
Math.abs(int1);
Math.abs(int2);
Math.abs(float1);
Math.abs(float2);
pending…
abs = Math.abs
abs(int1);
abs(int2);
abs(float1);
abs(float2);
pending…
* -1
(int1 < 0 ? int1 * -1 : int1);
(int2 < 0 ? int2 * -1 : int2);
(float1 < 0 ? float1 * -1 : float1);
(float2 < 0 ? float2 * -1 : float2);
pending…
minus
(int1 < 0 ? -int1 : int1);
(int2 < 0 ? -int2 : int2);
(float1 < 0 ? -float1 : float1);
(float2 < 0 ? -float2 : float2);
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