Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
For Each comparison
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser:
Chrome 131
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
lodash forEach
779.2 Ops/sec
Array.prototype.forEach()
926.2 Ops/sec
Traditional for loop
951.9 Ops/sec
Custom Array.prototype.forEach()
1036.5 Ops/sec
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.2/lodash.min.js'></script>
Script Preparation code:
var count = 100000 var myArray = []; for (var i = 0; i < count; i++) { myArray.push(Math.random() * 5) } Array.prototype.forEach2=function(a){ var l=this.length; for(var i=0;i<l;i++)a(this[i],i) }
Tests:
lodash forEach
_.forEach(myArray, (value, index) => { myArray[index] = value + 1; });
Array.prototype.forEach()
myArray.forEach((value, index) => { myArray[index] = value + 1; });
Traditional for loop
for (var index = 0; index < myArray.length; index++) { myArray[index] = myArray[index] + 1; }
Custom Array.prototype.forEach()
myArray.forEach2((value, index) => { myArray[index] = value + 1; });