Y.Object.each vs for loop (v9)

Revision 9 of this benchmark created on


Description

Y.Object.each vs for loop

Preparation HTML

<script type="text/javascript" src="//yui.yahooapis.com/combo?3.13.0/build/yui/yui-min.js"></script>
<script>
  var properties = 10;
  var obj = {};
  var sum = 0;
  var i = 0;
  var prop;
  
  while (i < properties) {
   obj['' + i] = i++;
  }
  Y = YUI().use('lang');
</script>

Test runner

Ready to run.

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

Revisions

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