Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
my Array.from() vs new Array()
(version: 0)
Testing the difference between creating filled arrays.
Comparing performance of:
new Array() vs Array.from()
Created:
4 years ago
by:
Guest
Jump to the latest result
Tests:
new Array()
new Array(500).fill(null)
Array.from()
Array.from({ length: 500 }, () => null)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
new Array()
Array.from()
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
10 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Browser/OS:
Chrome 137 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
new Array()
2145714.8 Ops/sec
Array.from()
98483.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks! **What is being tested?** The provided benchmark tests two ways to create filled arrays in JavaScript: 1. **new Array()**: This method creates an empty array and then fills it with null values using the `fill()` method. 2. **Array.from()**: This method creates a new array from an iterable (in this case, an object) and fills it with null values using a callback function. **Options being compared** The two options being compared are: * `new Array()`: A traditional way of creating arrays in JavaScript. * `Array.from()`: A more modern way of creating arrays, introduced in ECMAScript 2015 (ES6). **Pros and cons of each approach:** 1. **new Array()**: * Pros: + Wide browser support across all versions of Internet Explorer to Chrome. + Easy to read and write. * Cons: + Can be slower than `Array.from()` due to the overhead of creating an empty array and then filling it. 2. **Array.from()**: * Pros: + More concise and expressive code. + Can be faster than `new Array()` because it avoids the overhead of creating an empty array. * Cons: + Requires ECMAScript 2015 (ES6) or later support, which may not be available in older browsers. **Library and purpose** In this benchmark, a library is not explicitly mentioned. However, `Array.from()` uses a built-in JavaScript function to create an array from an iterable. **Special JS feature or syntax** There are no special JavaScript features or syntaxes used in this benchmark other than the use of ECMAScript 2015 (ES6) syntax for `Array.from()`.
Related benchmarks:
Array.from() vs new Array()
Array.from() vs new Array() - empty
Array.from() vs new Array().map()
Array.from() vs new A
Comments
Confirm delete:
Do you really want to delete benchmark?