Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array fill vs fill/from vs apply vs join
(version: 0)
Fill an array with repeated elements
Comparing performance of:
Fill vs Fill/From vs Apply vs Join (only with single characters!)
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
Fill
new Array(5).fill('abc');
Fill/From
Array.from({ length: 5 }).fill('abc')
Apply
Array.apply(null, Array(3)).map(_ => 'abc')
Join (only with single characters!)
Array(6).join('a').split('');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Fill
Fill/From
Apply
Join (only with single characters!)
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0
Browser/OS:
Firefox 120 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Fill
67426752.0 Ops/sec
Fill/From
31709952.0 Ops/sec
Apply
9934439.0 Ops/sec
Join (only with single characters!)
6197903.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON data and explain what each part represents. **Benchmark Definition** The `Name` field specifies the name of the benchmark, which in this case is "Array fill vs fill/from vs apply vs join". The `Description` field provides a brief description of the benchmark, indicating that it's comparing different ways to fill an array with repeated elements. The `Script Preparation Code` and `Html Preparation Code` fields are empty, suggesting that no specific code needs to be written before running the benchmark. This is likely because the test cases use built-in JavaScript methods or functions to generate arrays. **Individual Test Cases** Each test case represents a different way to fill an array with repeated elements: 1. **Fill**: Uses the `new Array(5).fill('abc')` syntax, which creates a new array with 5 elements, all set to the string 'abc'. 2. **Fill/From**: Uses the `Array.from({ length: 5 }).fill('abc')` syntax, which uses the `Array.from()` method to create an array from an object with a specified length, and then fills it with repeated elements. 3. **Apply**: Uses the `Array.apply(null, Array(3)).map(_ => 'abc')` syntax, which applies the `Array.prototype.map()` function to an array created using `Array.apply()`. 4. **Join (only with single characters!)**: Uses the `Array(6).join('a').split(';')` syntax, which creates an array with 6 elements, joins them together into a string with 'a' as the separator, and then splits the resulting string into individual elements. **Test Results** The test results are presented in a JSON format, showing the following information for each browser: * `RawUAString`: The raw User Agent string sent by the browser. * `Browser`: The name of the browser. * `DevicePlatform`: The type of device platform (Desktop or Mobile). * `OperatingSystem`: The operating system used. * `ExecutionsPerSecond`: The average number of executions per second for each test case. **Library and Special JS Features** None of the provided JSON data mentions specific libraries, but it does use built-in JavaScript methods such as: * `Array.prototype.fill()` * `Array.from()` * `Array.prototype.map()` The `apply()` method is a special method in JavaScript that can be used to invoke a function with an array as its first argument. **Alternatives** Other alternatives for filling arrays with repeated elements include: * Using the spread operator (`[...new Array(5)]`) or the repeat function (if available) to create an array. * Using a loop to push each element onto the array. * Using a library like Lodash, which provides various utility functions, including `repeat()`.
Related benchmarks:
Array(length).fill() vs Array.from({ length: length })
Array() vs new Array() fill
Array() vs Array.from() fill
fill array with value: map(callback) vs fill(value) 2
Array Spread vs Fill vs New Array
Comments
Confirm delete:
Do you really want to delete benchmark?