Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
findIndex vs _sortedIndexBy vs custom sortedIndexBy
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/124.0.0.0 Safari/537.36 Edg/124.0.0.0
Browser:
Chrome 124
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
lodash sortedIndexBy()
3175069.8 Ops/sec
native findIndex()
285171.7 Ops/sec
custom sortedIndexBy()
725579.6 Ops/sec
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var arr = []; for(let i = 0; i < 5000; i++){ arr.push({ price: i }) } function sortedIndexBy(array, comparator) { let min = 0 let max = array.length let index = Math.floor((min + max) / 2) while (max > min) { if (comparator(array[index]) < 0) { max = index } else { min = index + 1 } index = Math.floor((min + max) / 2) } return index - 1 }
Tests:
lodash sortedIndexBy()
_.sortedIndexBy(arr, {price: 4242}, 'price')
native findIndex()
arr.findIndex((o) => o.price === 4242)
custom sortedIndexBy()
sortedIndexBy(arr, (o) => (4242 > o.price ? 1 : (4242 < o.price ? -1 : 0)))