gcheck

JavaScript performance comparison

Test case created by Ze

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var Particle = function(options) {
        this.rad = options.rad || 1;
        this.mass = options.mass || 1;
        this.x = options.x || 0;
        this.y = options.y || 0;
        this.vx = options.vx || 0;
        this.vy = options.vy || 0;
        this.fx = 0;
        this.fy = 0;
        };
    var parray = [];
    for (var i = 10; i >= 1; i -= 1) {
      parray.push(new Particle({
        x: Math.random() * 400,
        y: Math.random() * 400,
        rad: 5,
        mass: 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
Trigo
for (var i = 0, pLen = parray.length; i < pLen - 1; i += 1) {
  var mainParticle = parray[i];
  for (var k = i + 1; k < pLen; k += 1) {
    var otherParticle = parray[k];
    var dx = otherParticle.x - mainParticle.x;
    var dy = otherParticle.y - mainParticle.y;
    var dPowed = dx * dx + dy * dy;
    if (dPowed > 120) {
      var angle = Math.atan2(dy, dx);
      //var d = Math.sqrt(dPowed);
      var force = 250 * otherParticle.mass * mainParticle.mass / dPowed;
      var fx = force * Math.cos(angle);
      var fy = force * Math.sin(angle);
      //var fx = force * dx / d;
      //var fy = force * dy / d;
      otherParticle.fx -= fx;
      otherParticle.fy -= fy;
      mainParticle.fx += fx;
      mainParticle.fy += fy;
    }
  }
}
pending…
Pitago
for (var i = 0, pLen = parray.length; i < pLen - 1; i += 1) {
  var mainParticle = parray[i];
  for (var k = i + 1; k < pLen; k += 1) {
    var otherParticle = parray[k];
    var dx = otherParticle.x - mainParticle.x;
    var dy = otherParticle.y - mainParticle.y;
    var dPowed = dx * dx + dy * dy;
    if (dPowed > 120) {
      //var angle = Math.atan2(dy, dx);
      var d = Math.sqrt(dPowed);
      var force = 250 * otherParticle.mass * mainParticle.mass / dPowed;
      //var fx = force * Math.cos(angle);
      //var fy = force * Math.sin(angle);
      var fx = force * dx / d;
      var fy = force * dy / d;
      otherParticle.fx -= fx;
      otherParticle.fy -= fy;
      mainParticle.fx += fx;
      mainParticle.fy += fy;
    }
  }
}
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