particle sub system

JavaScript performance comparison

Revision 2 of this test case created by Ryan Lynd

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var velsXfloat = new Float32Array(1000);
    var velsXint16 = new Int16Array(1000);
    var velsXArr = new Array(1000);
    var spritesXfloat = new Float32Array(1000);
    var spritesXint16 = new Int16Array(1000);
    var spritesXArr = new Array(1000);
    var Sprite = function(i) {
        this.x = Math.random() * 100;
        this.vel = Math.random() * 100;
        };
    var sprites = [];
   
   
    for (var i = 0; i < spritesXfloat.length; i++) {
      spritesXfloat[i] = Math.random() * 100;
      spritesXArr[i] = Math.random() * 100;
      velsXfloat[i] = Math.random() * 100;
      velsXint16[i] = Math.random() * 100 * 100;
      velsXArr[i] = Math.random() * 100;
      spritesXint16[i] = ~~ (Math.random() * 100) * 100;
      sprites[i] = new Sprite(i);
    }
   
    // const for mod test
    var c = new Int16Array(10);
    c[0] = 100; // precision
    c[1] = 200 * 100;
    c[2] = 0.78 * 100;
    c[3] = 32 * 100;
    c[4] = 10.5 * 100;
};
</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
floatArr
var i = 1000;
while (i--) {
  spritesXfloat[i] = velsXfloat[i] * 200 / 0.78 + 32 - 10.5;
  var x = spritesXfloat[i];
}
pending…
int16Arr
var i = 1000;
while (i--) {
  spritesXint16[i] = (velsXfloat[i] * 200 / 0.78 + 32 - 10.5) * 100;
  var x = spritesXint16[i] / 100;
}
pending…
std. class
var i = 1000;
while (i--) {
  sprites[i].x = sprites[i].vel * 200 / 0.78 + 32 - 10.5;
  var x = sprites[i].x;
}
pending…
intArr - mod
// intArr - mod
var i = 1000;
while (i--) {
  spritesXint16[i] = velsXint16[i] * c[1] / c[2] + c[3] - c[4];
  var x = spritesXint16[i] / c[0];
}
pending…
Native array
//native Array
var i = 1000;
while (i--) {
  spritesXArr[i] = velsXArr[i] * 200 / 0.78 + 32 - 10.5;
  var x = spritesXfloat[i];
}
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