Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
fill vs push multiple
(version: 0)
Comparing performance of:
fill vs push
Created:
4 years ago
by:
Guest
Jump to the latest result
Tests:
fill
let a = Array(600000).fill(16); let b = Array(600000).fill().map((_, idx) => 16 * idx);
push
let a = []; let b = []; for(let i = 0; i< 600000;i++) { a.push(16); b.push(i*16); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
fill
push
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks! **What is being tested?** MeasuresThat.net is testing two different approaches to create an array of 600,000 elements and fill it with a constant value (in this case, `16`). The two approaches are: 1. **`fill()` method**: Creating an empty array using `Array(600000).fill(16)`. 2. **`push()` method in a loop**: Creating an empty array `[]`, then looping 600,000 times to push `16` and another value (`i*16`) onto the end of the array. **Options being compared** The two approaches are being compared for performance differences. **Pros and Cons:** 1. **`fill()` method**: * Pros: + Faster execution time due to optimized implementation by the JavaScript engine. + More concise and readable code. * Cons: + May not work as expected in certain situations (e.g., when working with large arrays that don't fit in memory). 2. **`push()` method in a loop**: * Pros: + More flexible and reusable, as it doesn't rely on the `fill()` method. * Cons: + Longer execution time due to the looping overhead. + Less concise and less readable code. **Library usage** None of the provided benchmark test cases uses any libraries. **Special JavaScript features or syntax** There are no special JavaScript features or syntax being used in these tests. However, it's worth noting that some modern JavaScript engines (like V8) have optimized implementations for certain array operations, which may affect performance. **Other alternatives** If you wanted to create an array of 600,000 elements and fill it with a constant value using alternative approaches, here are a few options: 1. **`Array.from()` method**: `Array.from(new Array(600000), () => 16)` 2. **`Map` object**: `new Map().set(16, new Array(600000).fill(0))` 3. **`reduce()` method**: `(arr, acc) => arr.reduce((acc, _, idx) => (acc[idx] = 16), {})` Keep in mind that these alternatives may have different performance characteristics and may not be as concise or readable as the original `fill()` method. I hope this explanation helps!
Related benchmarks:
spread vs push - simple3
fill vs push multiple small
fill + map vs push
fill array with value: map(callback) vs fill(value) 2
Comments
Confirm delete:
Do you really want to delete benchmark?