forvswhile

Benchmark created by dhayes on


Preparation HTML

<script>

var fastForEach = function fastForEach (subject, fn, thisContext) {
    var length = subject.length,
        i;
    for (i = 0; i < length; i++) {
      fn.call(thisContext, subject[i], i, subject);
    }
  },
    
  whileForEach = function (subject, fn, thisContext) {
    
    var upto = subject.length - 1,
        i = 0;
    
    while (i++ < upto) {
      fn.call(thisContext, subject[i], i, subject);
    }
    
  },
  
  a = [1,2,3,4,5,6,7,8,9,10],
  
  noop = function() {};

</script>

Test runner

Ready to run.

Testing in
TestOps/sec
fast.js
fastForEach(a, noop);
ready
while
whileForEach(a, noop);
ready

Revisions

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