aba

JavaScript performance comparison

Test case created by Simon

Preparation code

<script>
function A() {
  this._q = null;
  this._w = null;
  this._e = null;
  this._r = null;
  this._t = null;
  this._y = null;
  this._u = null;
}

A.prototype.getQ = function(){
  return this._q;
}

A.prototype.setQ = function(val){
  this._q = val;
}

function B() {
  this._placeholder = null;
}

B.prototype.setup = function() {
  this._placeholder = {
    _q: null,
    _w: null,
    _e: null,
    _r: null,
    _t: null,
    _y: null,
    _u: null
  }
}

B.prototype.getQ = function() {
  return this._placeholder === null ? null : this._placeholder._q;
}

B.prototype.setQ = function(val) {
  if (this._placeholder === null) this.setup();
  this._placeholder._q = val;
}
</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
A
var a = [];
for (var i = 0; i < 100; i++) {
  var b = new A();
  if (i < 10) b.setQ('yay');
  a.push(b);
}
pending…
B
var a = [];
for (var i = 0; i < 100; i++) {
  var b = new B();
  if (i < 10) b.setQ('yay');
  a.push(b);
}
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