Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36
Chrome 67
Windows
Desktop
6 years ago
Test name Executions per second
lodash.each 57605.9 Ops/sec
native 55117.1 Ops/sec
for loop 2894.8 Ops/sec
HTML Preparation code:
AخA
 
1
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
2
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>
Script Preparation code:
x
 
// Populate the base array
var arr = [];
for (var i = 0; i < 1000; i++) {
  arr[i] = i;
}
function fn(a) {
  return a * 2 * 5;
}
      
Tests:
  • lodash.each

     
    _.forEach(arr,fn)
  • native

     
    arr.forEach(fn)
  • for loop

     
    for(i=0;i<arr.length;i++)
      fn(arr[i]);