aba

JavaScript performance comparison

Revision 3 of this test case created by dievardump

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('_q');
}

B.prototype.setQ = function(val) {
  return  this.placeholder('_q', val);
}

B.prototype.placeholder = function (name, val) {
    if (typeof val === 'undefined') {
        if (this._placeholder === null) {
            return null;
        } else {
            return this._placeholder[name];
        }
    } else if (this._placeholder === null) {
        this.setup();
    }
    this._placeholder[name] = val;

    return this._placeholder[name];
}
</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();
  a.push(b);
}
pending…
B
var a = [];
for (var i = 0; i < 100; i++) {
  var b = new B();
  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