Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
new Array(length).fill().map vs Array.from({ length }, callback)
(version: 1)
Comparing performance of:
new Array + fill vs Array.from
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
/*your preparation JavaScript code goes here To execute async code during the script preparation, wrap it as function globalMeasureThatScriptPrepareFunction, example:*/ async function globalMeasureThatScriptPrepareFunction() { // This function is optional, feel free to remove it. // await someThing(); } var arr = ['', '', '']; const ARRAY_LENGTH = 10000;
Tests:
new Array + fill
new Array(ARRAY_LENGTH).fill(0).map((_, index) => index)
Array.from
Array.from({ length: ARRAY_LENGTH }, (_, index) => index)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
new Array + fill
Array.from
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 18_2_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.2 Mobile/15E148 Safari/604.1
Browser/OS:
Mobile Safari 18 on iOS 18.2.1
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
new Array + fill
37061.2 Ops/sec
Array.from
67548.2 Ops/sec
Related benchmarks:
Array creation
empty an array in JavaScript?
reate array by lenght
Assigning new variable
Float32Array Vec3 init
Test array concat
Test array concat with larger array
213find vs findIndex vs some (Array prototype methods)
new Array(length).fill vs Array.from({ length })
Comments
Confirm delete:
Do you really want to delete benchmark?