Test name | Executions per second |
---|---|
lodash.each | 57605.9 Ops/sec |
native | 55117.1 Ops/sec |
for loop | 2894.8 Ops/sec |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>
// Populate the base array
var arr = [];
for (var i = 0; i < 1000; i++) {
arr[i] = i;
}
function fn(a) {
return a * 2 * 5;
}
_.forEach(arr,fn)
arr.forEach(fn)
for(i=0;i<arr.length;i++)
fn(arr[i]);