Ext.each vs Native

JavaScript performance comparison

Revision 2 of this test case created

Preparation code

<script src="http://cdn.sencha.com/ext-4.1.1-gpl/ext-all-debug.js">
</script>
<script>
Benchmark.prototype.setup = function() {
    var obj = {};
    i = 0
    doSomething = function() {}
    opt = function(object, fn, scope) {
      if ('forEach' in Array.prototype && typeof Object.keys === "function") {
        Object.keys(object).every(function() {
          return (fn.apply(this, arguments) !== false);
        }, scope);
      } else {
        for (var property in object) {
          if (object.hasOwnProperty(property)) {
            if (fn.call(scope || object, property, object[property], object) === false) {
              return;
            }
   
          }
        }
      }
    };
    scope = {
      a: '123'
    };
   
    for (i = 0; i < 1000; i++) {
      obj['k' + i] = 'val' + i;
    }
};
</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
Native for-in Object
for (var i in obj) {
  if (obj.hasOwnProperty(i)) {
    doSomething(obj[i]);
    if (obj[i] === 'val500') {
      break;
    }
  }
}
pending…
Native for-in Object without prototype check
for (var i in obj) {
  doSomething(obj[i]);
  if (obj[i] === 'val500') {
    break;
  }
}
pending…
Ext.Object.each without scope
Ext.Object.each(obj, function(item) {
  doSomething(item);
  if (item === 'val500') {
    return false;
  }
});
pending…
Ext.Object.each with scope
Ext.Object.each(obj, function(item) {
  doSomething(item);
  if (item === 'val500') {
    return false;
  }
}, this);
pending…
ECMAScript 5 every without scope
Object.keys(obj).every(function(key) {
  doSomething(obj[key]);
  return obj[key] !== 'val500';
});
pending…
ECMAScript 5 every with scope
Object.keys(obj).every(function(key) {
  doSomething(obj[key]);
  return obj[key] !== 'val500';
}, this);
pending…
Best Combined without scope
opt(function(item) {
  doSomething(item);
  return item !== 'val500';
});
pending…
Best Combined with scope
opt(function(item) {
  doSomething(item);
  return item !== 'val500';
}, scope);
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