Comparación forin,keys,OwnpropertyNames,foreach (v2)

Revision 2 of this benchmark created by José Luis Junco L. on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
var a  = {},j;
for (var i=0;i<50;i++){a['Componente'+i] = 'Componente'+i}

</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Object.getOwnPropertyNames()
for (var i = 0, arr = Object.getOwnPropertyNames(a); i < arr.length; i++) {
  (function() {
    j = a[arr[i]];
  })()
}
ready
Object.keys()
for (var i = 0, arr = Object.keys(a); i < arr.length; i++) {
  (function() {
    j = a[arr[i]];
  })()
}
ready
for ... in
for (var i in a) {
  j = a[i];
}
ready
$.each()
$.each(a, function(k, v) {
  j = v;
})
ready

Revisions

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

  • Revision 2: published by José Luis Junco L. on