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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 Edg/140.0.0.0
Browser:
Chrome 140
Operating system:
Windows
Device Platform:
Desktop
Date tested:
7 months ago
Test name
Executions per second
lodash.forEach
6004991.5 Ops/sec
custom foreach
11798779.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 } })