Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
find() vs for...of vs for-loop BIG
(version: 0)
Testing the difference between native loops and find()
Comparing performance of:
for vs for of vs find vs for each
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<div id='test'></div>
Tests:
for
var arr = ['hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'b']; let val; for(i=0; i<arr.length; i++){ var value = arr[i]; if (value === 'b') { val = value; break; } }
for of
var arr = ['hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'b']; let val; for (var value of arr) { if (value === 'b') { val = value; break; } }
find
var arr = ['hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'b']; let val = arr.find(node => node.id === 'b');
for each
var arr = ['hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'hello', 'a', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'b']; let val; arr.forEach( value => { if (value === 'b') { val = value; } });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
for
for of
find
for each
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!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
A dramatic reading of the benchmark results! It seems we have three test cases: `find`, `for each`, and `for of`. The `for each` test case has the lowest execution speed, followed by `for of`, and then `find`. Here's a summary: * **For Each**: 132149.953125 executions per second ( highest latency) * **For Of**: 92228.546875 executions per second * **Find**: 52731.2109375 executions per second It looks like the `for each` test case is the slowest, likely due to the use of a manual loop (`arr.forEach`) which can be less efficient than native iterations. What's the context for these benchmark results? Are you optimizing JavaScript performance in Firefox 90?
Related benchmarks:
loop vs recursion
Array fill foreach, vs for i loop
foreach vs for..of
foreach vs for...of
Array fill vs for i loop
Comments
Confirm delete:
Do you really want to delete benchmark?