Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Init array with fill map, vs for i loop
(version: 0)
People tend to use array fil and then foreach, we know foreach is faster than a for loop, but is it also faster if you use array fill first?
Comparing performance of:
for vs fill and map
Created:
one year ago
by:
Guest
Go to the latest result
Script Preparation code:
var iterations = 10000;
Tests:
for
res = [] for (i = 0; i < iterations; i++) { res.push(i); }
fill and map
res = Array(iterations).fill(null).map((value, index) => index);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
for
fill and map
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:131.0) Gecko/20100101 Firefox/131.0
Browser/OS:
Firefox 131 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
fill and map
9K/s
for
4K/s
View exact numbers
Test name
Executions per second
✓
fill and map
8,796 Ops/sec
for
3,576 Ops/sec
Related benchmarks
Array loop vs for of loop vs foreach vs map (2)
Array loop: forEach vs for vs map vs for of entries
Array loop vs foreach vs map with large array
Comments
Confirm delete:
Do you really want to delete benchmark?