Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
12132132132131243214124
(version: 0)
Comparing performance of:
from vs fill
Created:
one year ago
by:
Guest
Jump to the latest result
Tests:
from
let n = 10000, length = 50; const result = []; for (let i = 0; i < n; ++i) { result.push(Array.from({length}, _ => length)); }
fill
let n = 10000, length = 50; const result = []; for (let i = 0; i < n; ++i) { result.push(Array(length).fill(length)); }
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 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36
Browser/OS:
Chrome 128 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
from
38.2 Ops/sec
fill
415.3 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what's being tested. **Benchmark Overview** The benchmark is designed to compare two approaches for creating arrays of repeated values: using `Array.from()` with a callback function (`_ => length`) versus using `Array(length).fill(length)`. **Approaches Compared** 1. **`Array.from()` with a callback function**: This approach uses the `Array.from()` method, which takes an array-like object and converts it into a new array. The callback function `_ => length` is applied to each element of the resulting array, effectively repeating the value `length`. 2. **`Array(length).fill(length)`**: This approach creates a new array with `length` elements and then fills each element with the value `length`. **Pros and Cons of Each Approach** 1. **`Array.from()` with a callback function**: * Pros: More concise, readable code. * Cons: May be slower due to the overhead of creating a callback function. 2. **`Array(length).fill(length)`**: * Pros: Faster, as it creates an array and fills it in a single operation. * Cons: Less readable code. **Other Considerations** * The `from` method is part of the ECMAScript standard, so it's supported by most modern browsers. However, some older browsers might not support it. * The `fill()` method is also widely supported, but its behavior can vary depending on the browser and version. **Library Used** None in this case, as both approaches use built-in JavaScript methods. **Special JS Features or Syntax** The benchmark uses a syntax feature common to modern JavaScript: template literals (`\r\n`). However, it's worth noting that older browsers might not support this feature or might interpret it differently. **Benchmark Preparation Code and Test Cases** The benchmark preparation code is empty, as the script itself contains all the necessary logic. The test cases are defined in the `Individual test cases` section, which describes two separate scenarios: 1. **"from"`**: This test case uses the `Array.from()` method with a callback function. 2. **"fill"`**: This test case uses the `Array(length).fill(length)` approach. **Alternatives** If you wanted to run this benchmark in a different environment, you could consider using: * A JavaScript engine like V8 or SpiderMonkey (which powers Firefox) * A testing framework like Jest or Mocha * A benchmarking library like Benchmark.js Keep in mind that the specific implementation details might vary depending on your chosen platform and tools.
Related benchmarks:
BigNumber.js Shiftby vs. Divide
parseInt vs toString vs unary(+)
JS BigInt big number performance vx4
Verifica CNPJ
String to number, parseInt, +, or * 1
Comments
Confirm delete:
Do you really want to delete benchmark?