for vs forEach (v189)

Revision 189 of this benchmark created on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>

Setup

var i,
    value,
    length,
    values = {},
    sum = 0,
    context = values;
  
  
  for (i = 0; i < 10000; i++) {
    values[i] = Math.random();
  }
  
  function add(val) {
    sum += val;
  }

Teardown



            i = 0;
  value = 0;
  length = 0;
  values = {};
  sum = 0;
        
  

Test runner

Ready to run.

Testing in
TestOps/sec
for cached length
for (var i = 0, l = values.length; i < l; ++i) {
  sum += values[i];
}
ready
for
for (var i = 0; i < values.length; i++) {
  sum += values[i];
}
ready

Revisions

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