GC-performance

JavaScript performance comparison

Test case created

Preparation code

<script>
window.Vector = function(x,y) {
  this.x = x;
  this.y = y;
};

Vector.prototype.copy = function () {
  return new Vector(x, y);
};

Vector.prototype.set(vec) {
  this.x = vec.x;
  this.y = vec.y;
};
Vector.prototype.scale(num) {
  this.x *= num;
  this.y *= num;
  return this;
};
</script>
<script>
Benchmark.prototype.setup = function() {
    var tmp = new Vector(0, 0);
    var momentum = new Vector(0, 0);
    var velocity = new Vector(0, 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
copy
for (var i = 0; i < 1000; i++) {
  momentum.x = i;
  velocity.set(momentum.copy().scale(2));
}
pending…
helper
for (var i = 0; i < 1000; i++) {
  momentum.x = i;
  tmp.set(momentum);
  velocity.set(temp.scale(2));
}
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