Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
find() vs for...of vs for-loop simple
(version: 0)
Benchmark.js
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
Go 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
Array.find()
30.4M/s
for-loop
14.9M/s
for..of
9.4M/s
View exact numbers
Test name
Executions per second
✓
Array.find()
30,372,066 Ops/sec
for-loop
14,871,933 Ops/sec
for..of
9,376,099 Ops/sec
Related benchmarks
Object arrays: findIndex vs for loop
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?