Y.Object.each vs for loop (v8)

Revision 8 of this benchmark created by Daniel Stockman on


Description

Y.Object.each vs for loop

Preparation HTML

<script src="https://yui.yahooapis.com/combo?3.11.0/yui/yui-min.js"></script>
<script>
  var properties = 1e6;
  var obj = {};
  var i = 0;
  
  while (i < properties) {
    obj['' + i] = i++;
  }
  
  Y = YUI().use('*');
</script>

Setup

var prop;
    var sum = 0;

Teardown


    sum = null;
    prop = null;
  

Test runner

Ready to run.

Testing in
TestOps/sec
Y.Object.each
Y.Object.each(obj, function (v, k) {
  sum += v;
});
ready
native for loop
for (prop in obj) {
  if (obj.hasOwnProperty(prop)) {
    sum += obj[prop];
  }
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.