Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Initialize 2d array
(version: 0)
Comparing performance of:
Functional vs New array vs Uint8 array vs Push destructured row vs Push row (closure)
Created:
3 years ago
by:
Guest
Jump to the latest result
Tests:
Functional
const arr1 = new Array(100).fill().map(()=>new Array(100).fill().map(()=>100));
New array
const arr3 = new Array(100); for (let i=0;i<100;i++) { arr3[i] = new Array(100); for (let j=0;j<100;j++) { arr3[i][j] = 100; } }
Uint8 array
const arr4 = new Uint8Array(100); for (let i=0;i<100;i++) { arr4[i] = new Array(100); for (let j=0;j<100;j++) { arr4[i][j] = 100; } }
Push destructured row
const arr5 = []; for (let i=0;i<100;i++) { const row = []; for (let j=0;j<100;j++) { row.push(100); } arr5.push([...row]); }
Push row (closure)
const arr6 = []; for (let i=0;i<100;i++) { const row = []; for (let j=0;j<100;j++) { row.push(100); } arr6.push(row); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
Functional
New array
Uint8 array
Push destructured row
Push row (closure)
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):
Measuring the performance of JavaScript benchmarks is crucial to understand the efficiency of different approaches in various scenarios. **Benchmark Definition JSON** The provided benchmark definition json represents a 2D array initialization task, which is used as the basis for comparing different methods of creating and populating a 2D array. **Test Cases** There are four test cases that compare different approaches to create and populate a 2D array: 1. **Functional**: Uses `Array.prototype.map()` twice to create a 2D array. * Pros: Concise, easy to understand. * Cons: May be less efficient due to repeated map operations. 2. **New Array**: Creates an outer array using `new Array(100)` and then populates it with inner arrays using a nested loop. * Pros: More explicit control over the data structure. * Cons: Requires more code and may be slower due to the overhead of creating arrays. 3. **Uint8Array**: Uses `Uint8Array` instead of regular arrays to create a 2D array. * Pros: May be faster due to the optimized performance of Uint8Array. * Cons: Does not provide any additional functionality beyond regular arrays. 4. **Push Destructured Row** and **Push Row (Closure)**: Uses array literals with push() method to populate a 2D array. * Pros: More concise and easier to read than the New Array approach. * Cons: May be less efficient due to the overhead of creating array literals. **Other Considerations** * Using libraries like Lodash can significantly impact performance, as it adds extra overhead. In this case, no library is used. * The use of ES6 features like `const`, `let`, and arrow functions does not appear to have a significant impact on performance in this benchmark. * Browser-specific optimizations may also play a role in the results. **Latest Benchmark Results** The provided latest benchmark results show that: * **Push Destructured Row** is the fastest approach, followed closely by **Uint8Array**, suggesting that using `new Array()` with Uint8Array can be an efficient way to create a 2D array. * **New Array** and **Functional** are slower due to the overhead of creating arrays and repeated map operations. Overall, this benchmark highlights the importance of considering performance optimization when writing JavaScript code.
Related benchmarks:
Create 2D Array
Create Square 2D Array
Create Square 2D Array Extended
Float32Array access
Comments
Confirm delete:
Do you really want to delete benchmark?