Multiply vs. divide with floats

JavaScript performance comparison

Revision 4 of this test case created by mgibsonbr

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function rint(max) {
      return Math.floor(Math.random() * max);
  }
  
  function rfloat(max) {
      return Math.random() * max;
  }

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Divide
// To avoid confounding....
var i1 = rint(65537);
var i2 = rint(65537);
var iinv = 1.0/i2;

var f1 = rfloat(65537);
var f2 = rfloat(65537);
var finv = 1.0/f2;

// The test itself
var a = i1 / i2;
pending…
Multiply
// To avoid confounding....
var i1 = rint(65537);
var i2 = rint(65537);
var iinv = 1.0/i2;

var f1 = rfloat(65537);
var f2 = rfloat(65537);
var finv = 1.0/f2;

// The test itself
var a = i1 * iinv;
pending…
Divide float
// To avoid confounding....
var i1 = rint(65537);
var i2 = rint(65537);
var iinv = 1.0/i2;

var f1 = rfloat(65537);
var f2 = rfloat(65537);
var finv = 1.0/f2;

// The test itself
var a = f1 / f2;
pending…
Multiply float
// To avoid confounding....
var i1 = rint(65537);
var i2 = rint(65537);
var iinv = 1.0/i2;

var f1 = rfloat(65537);
var f2 = rfloat(65537);
var finv = 1.0/f2;

// The test itself
var a = f1 * finv;
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.

0 Comments