Fast Array Foreach (v253)

Revision 253 of this benchmark created on


Setup

// Populate the base array
      var arr = [],
          forSmallest = 1000000;
    
      for (var i = 0; i < 1000; i++) {
        arr[i] = i;
      }
    
      function compare(smallest, current) {
        if (current < smallest) {
          smallest = current;
        }
        return smallest;
      }

Test runner

Ready to run.

Testing in
TestOps/sec
Array.ForEach
arr.reduce(compare, 1000000)
ready
For
for (var i = 0, len = arr.length; i < len; i++) {
  if (arr[i] < forSmallest) {
    forSmallest = arr[i];
  }
}
ready

Revisions

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