Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array Map alternatives
(version: 0)
Comparing performance of:
For loop bracket notation vs Map new notation vs Map old notation vs For loop push
Created:
8 years ago
by:
Guest
Jump to the latest result
Tests:
For loop bracket notation
var array1 = [1, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16], map1 = [], arrayLength = array1.length; for (var i = 0; i < arrayLength; i++) { map1[i] = array1[i] * 2; }
Map new notation
var array1 = [1, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16]; var map1 = array1.map(x => x * 2);
Map old notation
var array1 = [1, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16]; var map1 = array1.map(function (x) {return x * 2});
For loop push
var array1 = [1, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16], map1 = [], arrayLength = array1.length; for (var i = 0; i < arrayLength; i++) { map1.push(array1[i] * 2); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
For loop bracket notation
Map new notation
Map old notation
For loop push
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 long and detailed test result! It seems that the tests are comparing the performance of three different methods: 1. **Map new notation**: This method uses `map()` with an arrow function to create a new array with double values. 2. **Map old notation**: This method uses `map()` without an arrow function, which is the legacy syntax. 3. **For loop bracket notation**: This method uses a traditional `for` loop with brackets (`[]`) to iterate over the array and push double values to a new array. 4. **For loop push**: This method uses a traditional `for` loop without brackets to iterate over the array and push double values to a new array. The test results show that: * The **Map new notation** method is the fastest, with an average execution rate of 235,476 executions per second. * The **Map old notation** method is slightly slower, with an average execution rate of 230,885 executions per second. * The **For loop bracket notation** method is also slow, with an average execution rate of 229,712 executions per second. * The **For loop push** method is the slowest, with an average execution rate of 219,590 executions per second. It's worth noting that the performance differences between these methods are relatively small, and may not be significant in all cases. However, the results suggest that using `map()` with arrow functions (new notation) can provide a small performance boost compared to older syntax or traditional `for` loop methods.
Related benchmarks:
map vs flatMap
Array.find vs. Map.getss
Array.find vs. Map.get fork
Array.find vs. Map.get with very little items
SJ - Array.find vs. Map.get
Comments
Confirm delete:
Do you really want to delete benchmark?