Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
forEach vs map 4
(version: 0)
Comparing performance of:
forEach vs map
Created:
6 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
const numbersArray = [32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 14, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 17, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 16, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35];
Tests:
forEach
const numbersArray = [32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 14, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 17, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 16, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35]; let resultArray = []; numbersArray.forEach(element => { return resultArray.push(element * element); });
map
const numbersArray = [32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 14, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 17, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35, 32, 21, 22, 28, 16, 26, 31, 30, 27, 28, 33, 33, 34, 25, 35]; numbersArray.map(element => { return element * element; });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
forEach
map
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 benchmarking question! To analyze the results, I'll focus on the two test cases: `map` and `forEach`. **map**: The raw UA string is identical for both executions of `map`, which suggests that there's no difference in the browser's behavior between these two tests. The execution rate (per second) is significantly higher for `map` than `forEach`, indicating a performance advantage. **forEach**: In contrast, the raw UA string differs slightly between the two executions of `forEach`. This might indicate variations in browser behavior or interpretation of the JavaScript code. **Performance comparison**: - **map**: 1534.15 executions per second - **forEach**: 785.395 executions per second The results suggest that the `map` function is significantly faster than the `forEach` loop in this specific benchmarking scenario. Keep in mind that these results are not definitive and may depend on various factors, such as the JavaScript engine used by the browser or system-specific conditions.
Related benchmarks:
map vs for: too much data
find vs foreach large
forEach vs map large array
forEach vs map logged
Comments
Confirm delete:
Do you really want to delete benchmark?