Fast Array Foreach (v32)

Revision 32 of this benchmark created on


Preparation HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.js"></script>

Setup

// Populate the base array
      var arr = [], source=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
      for (var i = 0; i < 1000; i++) {
        arr[i] = i;
      }
    
      function someFn(i) {
        var length = 35,
        i,
        rString = '';
    
        for (i = 0; i < length; i+= 1) {
          rString += source[Math.floor(Math.random() * source.length)];
        }
        return rString;
      }

Test runner

Ready to run.

Testing in
TestOps/sec
Array.ForEach
arr.forEach(someFn)
ready
For
for (var i = 0, len = arr.length; i < len; i++) {
  someFn(arr[i]);
}
ready
For in
for (var i in arr) {
  someFn(arr[i]);
}
ready
Lodash
_.each(arr, someFn)
ready

Revisions

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