Float32Array vs var multiply

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var a = new Float32Array([1.000001, 1.000002]);
   
    var b = new Float32Array([0, 0]);
   
    var b0;
    var b1;
   
    var o = {x:0, y:0};
};
</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
float32
for (var i = 0; i < 100000; ++i) {
  b[0] = a[0];
  b[1] = a[1];
  a[0] = b[0] * b[1];
  b[0] = a[0];
  b[1] = a[1];
  a[0] = b[0] * b[1];
  b[0] = a[0];
  b[1] = a[1];
  a[0] = b[0] * b[1];
  b[0] = a[0];
  b[1] = a[1];
  a[0] = b[0] * b[1];
  b[0] = a[0];
  b[1] = a[1];
  a[0] = b[0] * b[1];
  b[0] = a[0];
  b[1] = a[1];
  a[0] = b[0] * b[1];
  b[0] = a[0];
  b[1] = a[1];
  a[0] = b[0] * b[1];
  b[0] = a[0];
  b[1] = a[1];
  a[0] = b[0] * b[1];
  b[0] = a[0];
  b[1] = a[1];
  a[0] = b[0] * b[1];
  b[0] = a[0];
  b[1] = a[1];
  a[0] = b[0] * b[1];
}
pending…
var
for (var i = 0; i < 100000; ++i) {
  b0 = a[0];
  b1 = a[1];
  a[0] = b0 * b1;
  b0 = a[0];
  b1 = a[1];
  a[0] = b0 * b1;
  b0 = a[0];
  b1 = a[1];
  a[0] = b0 * b1;
  b0 = a[0];
  b1 = a[1];
  a[0] = b0 * b1;
  b0 = a[0];
  b1 = a[1];
  a[0] = b0 * b1;
  b0 = a[0];
  b1 = a[1];
  a[0] = b0 * b1;
  b0 = a[0];
  b1 = a[1];
  a[0] = b0 * b1;
  b0 = a[0];
  b1 = a[1];
  a[0] = b0 * b1;
  b0 = a[0];
  b1 = a[1];
  a[0] = b0 * b1;
  b0 = a[0];
  b1 = a[1];
  a[0] = b0 * b1;
}
pending…
float32 direct
for (var i = 0; i < 100000; ++i) {
  a[0] = a[0] * a[1];
  a[0] = a[0] * a[1];
  a[0] = a[0] * a[1];
  a[0] = a[0] * a[1];
  a[0] = a[0] * a[1];
  a[0] = a[0] * a[1];
  a[0] = a[0] * a[1];
  a[0] = a[0] * a[1];
  a[0] = a[0] * a[1];
  a[0] = a[0] * a[1];
}
pending…
object
for (var i = 0; i < 100000; ++i) {
  o.x = a[0];
  o.y = a[1];
  a[0] = o.x * o.y;
  o.x = a[0];
  o.y = a[1];
  a[0] = o.x * o.y;
  o.x = a[0];
  o.y = a[1];
  a[0] = o.x * o.y;
  o.x = a[0];
  o.y = a[1];
  a[0] = o.x * o.y;
  o.x = a[0];
  o.y = a[1];
  a[0] = o.x * o.y;
  o.x = a[0];
  o.y = a[1];
  a[0] = o.x * o.y;
  o.x = a[0];
  o.y = a[1];
  a[0] = o.x * o.y;
  o.x = a[0];
  o.y = a[1];
  a[0] = o.x * o.y;
  o.x = a[0];
  o.y = a[1];
  a[0] = o.x * o.y;
  o.x = a[0];
  o.y = a[1];
  a[0] = o.x * o.y;
}
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment