Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.from() vs new Array().map()
(version: 0)
Testing the difference between creating filled arrays.
Comparing performance of:
new Array().map() vs Array.from()
Created:
2 years ago
by:
Guest
Go to the latest result
Tests:
new Array().map()
new Array(500).fill(0).map((_, i) => i)
Array.from()
Array.from({ length: 500 }, (_, i) => i)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
new Array().map()
Array.from()
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one month ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:151.0) Gecko/20100101 Firefox/151.0
Browser/OS:
Firefox 151 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
Array.from()
414K/s
new Array().map()
274K/s
View exact numbers
Test name
Executions per second
✓
Array.from()
413,730 Ops/sec
new Array().map()
274,028 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the explanation of the provided benchmark. **What is being tested?** The benchmark compares two approaches to creating filled arrays: `Array.from()` and `new Array().map()`. The goal is to determine which approach is faster in JavaScript. **Options compared:** 1. **`Array.from()`**: This method creates a new array from an iterable (in this case, an object with a `length` property). It's designed to be more flexible and efficient than traditional array creation methods. 2. **`new Array().map()`**: This approach uses the `map()` method to create a new array by applying a provided function to each element of an existing array (or in this case, creating a new empty array using `new Array()`). **Pros and cons:** * **`Array.from()`**: + Pros: - More concise and expressive syntax. - Designed for performance and flexibility. - Works with various iterables, not just arrays. + Cons: - May require additional library support (e.g., for older browsers). - Can be slower in some cases due to the overhead of creating an array from an iterable. * **`new Array().map()`**: + Pros: - Widely supported across browsers and JavaScript engines. - Simple and familiar syntax. + Cons: - Less concise and expressive than `Array.from()`. - May require more code to achieve the same result. **Library:** There is no explicit library mentioned in the benchmark definition or test cases. However, some browsers may use additional libraries or polyfills to support newer JavaScript features like `Array.from()`. **Special JS feature/syntax:** There are no special JavaScript features or syntaxes used in this benchmark beyond what's provided by the standard language specification.
Related benchmarks
Array.from() vs new Array() performance...
Array.from() vs new Array() - empty
Array.from() vs new Array() with index
Comments
Confirm delete:
Do you really want to delete benchmark?