Math.pow(float, 4) vs. multiplying float * float * float * float

JavaScript performance comparison

Revision 2 of this test case created by tomByrer

Info

v2: added test for assigning array lookup to a 't'emproary var.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var test_cases = [
        0,
        1,
        3/2,
        2/3,
        5/7,
        -9/6,
        Math.PI,
        Math.PI * 256,
        Math.PI * 65536,
        Math.PI * Math.E * 4294967296,
        Math.E, Math.SQRT2,
        Math.SQRT2 * 4294967296,
        Math.SQRT1_2,
        Math.LN2,
        Math.LN10,
        Math.LOG2E,
        Math.LOG10E,
        (1 + Math.sqrt(5)) / 2
    ];
};
</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
power: Math.pow(f, 4)
for (var i in test_cases) {
  Math.pow(test_cases[i], 4);
}
pending…
multiply: f*f*f*f
for (var i in test_cases) {
  test_cases[i] * test_cases[i] * test_cases[i] * test_cases[i];
}
pending…
mult: t outside
var t = 0.0;
for (var i in test_cases) {
  t = test_cases[i]
  t * t * t * t;
}
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