Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
find() vs for...of vs for-loop simple
(version: 0)
Testing the difference between native loops and find()
Comparing performance of:
for-loop vs for..of vs Array.find()
Created:
3 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<div id='test'></div>
Script Preparation code:
var arr = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.".split(" ");
Tests:
for-loop
let val; for(i=0; i<arr.length; i++){ var value = arr[i]; if (value === 'dolore') { val = value; break; } }
for..of
let val; for (var value of arr) { if (value === 'dolore') { val = value; break; } }
Array.find()
let val = arr.find(value => value === 'dolore');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
for-loop
for..of
Array.find()
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:138.0) Gecko/20100101 Firefox/138.0
Browser/OS:
Firefox 138 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
for-loop
14871933.0 Ops/sec
for..of
9376099.0 Ops/sec
Array.find()
30372066.0 Ops/sec
Related benchmarks:
Object arrays: findIndex vs for loop
Object arrays: find vs for loop
Object arrays: findIndex vs for loop (length cached)
Object arrays: findIndex vs for loop (Small amount of entries)
IndexOf vs Includes in string - larger string edition
Comments
Confirm delete:
Do you really want to delete benchmark?