Multiply vs divide / constant vs vars

JavaScript performance comparison

Revision 11 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var counter = 0,
      m1 = 0.25, m2 = 0.5, m3 = 0.1, m4 = 2,
      d1 = 4, d2 = 2, d3 = 10, d4 = 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
Dummy - ignore?
var r = counter++,
    x = r * 0.25,
    y = r * 0.5,
    z = r * 0.1,
    a = r * 2;
pending…
Multiply by Const
var r = counter++,
    x = r * 0.25,
    y = r * 0.5,
    z = r * 0.1,
    a = r * 2;
pending…
Multiply by Var
var r = counter++,
    x = r * m1,
    y = r * m2,
    z = r * m3,
    a = r * m4;
pending…
Divide by Const
var r = counter++,
    x = r / 4,
    y = r / 2,
    z = r / 10,
    a = r / 0.5;
pending…
Divide by Var
var r = counter++,
    x = r / d1,
    y = r / d2,
    z = r / d3,
    a = r / d4;
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