const a = [];
for (let i = 0; i < 10_000; i++) {
a.push([i]);
}
const a = [];
for (let i = 0; i < 10_000; i++) {
a.push(new Float32Array([i]));
}
const a = new Float32Array(10_000);
for (let i = 0; i < 10_000; i++) {
a[i] = new Float32Array([i]);
}
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
create arrays | |
create typed arrays | |
create typed arrays in typed array |
Test name | Executions per second |
---|---|
create arrays | 9808.0 Ops/sec |
create typed arrays | 1457.5 Ops/sec |
create typed arrays in typed array | 291.8 Ops/sec |
Let's break down the provided benchmarking test.
Benchmark Definition
The benchmark measures the performance of three approaches to create arrays and push data into them:
const a = []
) and then pushes elements onto it using the push()
method.push()
method.Options Compared
The benchmark compares the performance of three approaches:
Pros and Cons of Each Approach
Library Used
In this benchmark, the Float32Array
constructor is used to create typed arrays. Float32Array
is a built-in JavaScript class that represents a typed array of 32-bit floating-point numbers.
Special JS Feature or Syntax
This benchmark does not use any special JavaScript features or syntax beyond what's required for the standard library functions (e.g., push()
, new Float32Array()
).