Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
object key iteration - lodash vs native custom implementation
the custom code is basically what happens in lodash already - perhaps it's faster because lodash each has overhead deciding if something is an array or object
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Browser:
Chrome 133
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
lodash.forEach
4001531.8 Ops/sec
custom foreach
9230919.0 Ops/sec
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/lodash/4.16.0/lodash.min.js"></script>
Script Preparation code:
var values = {a: 123, b: 234, c: 445, d: 23, e: 234, f:234, g: 345, h: 34, i: 43}; var forEachObjectKey = (object, toRun) => { const keys = Object.keys(object) let length = keys.length let index = -1 while (length--) { index++ toRun(keys[index], (object)[keys[index]]) } }
Tests:
lodash.forEach
let count = 0; _.forEach(values, (v,i) => { if (i != null) { count+= i; } })
custom foreach
let count = 0 forEachObjectKey(values, (key, value) => { if (value != null) { count += value } })