Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.from vs Array.fill (with correct length)
(version: 1)
Comparing performance of:
from vs fill
Created:
one year ago
by:
Guest
Jump to the latest result
Tests:
from
let n = 10000, length = 100 let dontOptimizeMeBro = 0; for (let i = 0; i < n; ++i) { dontOptimizeMeBro += Array.from({length:length}).map((_, i) => i + 1).at(-1); } console.log(dontOptimizeMeBro)
fill
let n = 10000, length = 100 let dontOptimizeMeBro = 0; for (let i = 0; i < n; ++i) { dontOptimizeMeBro += Array(length).fill(0).map(i => i + 1).at(-1); } console.log(dontOptimizeMeBro)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
from
fill
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:134.0) Gecko/20100101 Firefox/134.0
Browser/OS:
Firefox 134 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
from
166.5 Ops/sec
fill
112.0 Ops/sec
Related benchmarks:
else vs continue vs short if
For Loop Different Approaches
TestArrayAllocationsAndFilling
TestArrayAllocation
TestArrayAllocationv2
Another array[len - 1] vs array.at(-1)
Array.from vs Array.fill (zeroes)
Set replace
12132132132131243214124
Comments
Confirm delete:
Do you really want to delete benchmark?