Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Find vs Math
(version: 5)
Using Array.find vs converting desired input into an index.
Comparing performance of:
Array.find() vs Math
Created:
8 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
window.mileage = [ { name: '1000 mileage', mileage: '1000', description: 'mileage-description', }, { name: '2000 mileage', mileage: '2000', description: 'mileage-description 2', }, { name: '3000 mileage', mileage: '3000', description: 'mileage-description 3', } ]; function generateRandomInput() { // Just some test thing to make sure the specific index isn't a factor as to which is faster return Math.floor(Math.random() * 3000) }
Tests:
Array.find()
mileage.find(obj => parseInt(obj.mileage, 10) >= generateRandomInput())
Math
const index = Math.floor(generateRandomInput()/1000); mileage[index];
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Array.find()
Math
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
Get max from an array of numbers (Math.max vs. iteration)
Get max from an array of numbers (Math.max vs. iteration) V2
Get max from an array of numbers (Math.max vs. iteration) V3
Math.random vs Crypto.getRandomValues for 10k values
new Array() vs Array.from() with random data
Comments
Confirm delete:
Do you really want to delete benchmark?