Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
meanBy vs native vs using sumBy
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/136.0.0.0 Safari/537.36
Browser:
Chrome 136
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
avgByNative
77559872.0 Ops/sec
avgByLodash
52358424.0 Ops/sec
avgByLodashUsingSumBy
13413124.0 Ops/sec
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js'></script>
Script Preparation code:
const smallArray = Array.from({ length: 10 }, (_, i) => i); // 1. Native avgBy (using reduce for sum and dividing by length) const avgByNative = (arr, fn) => { const sum = arr.reduce((acc, item) => acc + fn(item), 0); return sum / arr.length; }; // 2. Lodash meanBy const avgByLodash = (arr, fn) => _.meanBy(arr, fn); // 3. Lodash using sumBy and dividing by length const avgByLodashUsingSumBy = (arr, fn) => { const sum = _.sumBy(arr, fn); return sum / arr.length; };
Tests:
avgByNative
avgByNative(smallArray, item => item.value)
avgByLodash
avgByLodash(smallArray, item => item.value)
avgByLodashUsingSumBy
avgByLodashUsingSumBy(smallArray, item => item.value)