Object.observe polyfill sandbox

JavaScript performance comparison

Test case created by Misko Hevery and last updated

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function rndFieldName() {
    return 'a' + Math.floor(Math.random()*999).toString(16);
  }
  
  function rndObj() {
    var field = rndFieldName();
    var obj = { field: field };
    obj[field] = 1;
    return obj;
  }
  
  function createRow(last) {
    var lastValue = 1;
    var obj = rndObj();
    var field = obj.field;
    return (last.next = {
      lastValue: lastValue,
      obj: obj,
      field: field,
      getter: new Function('s', 'return s.' +field),
      check: function() {
        if (obj[field] !== lastValue) throw 'dirty';
      },
      next: null
    });
  }
  
  var head = createRow({});
  var current = head;
  for(var i=1; i<10000; i++) {
    current = createRow(current);
  }

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
baseline
var current = head;
while(current !== null) {
  if (current.obj[current.field] !== current.lastValue) throw 'dirty';
  current = current.next;
}
pending…
function check
var current = head;
while(current !== null) {
  current.check();
  current = current.next;
}
pending…
getter
var current = head;
while(current !== null) {
  if (current.getter(current.obj) !== current.lastValue) throw 'dirty';
  current = current.next;
}
pending…
iterate only
var current = head;
while(current !== null) {
  current = current.next;
}
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.

0 Comments