Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Push to: array vs float32array performance test
(version: 0)
Comparing performance of:
create arrays vs create typed arrays vs create typed arrays in typed array
Created:
one year ago
by:
Registered User
Jump to the latest result
Tests:
create arrays
const a = []; for (let i = 0; i < 10_000; i++) { a.push([i]); }
create typed arrays
const a = []; for (let i = 0; i < 10_000; i++) { a.push(new Float32Array([i])); }
create typed arrays in typed array
const a = new Float32Array(10_000); for (let i = 0; i < 10_000; i++) { a[i] = new Float32Array([i]); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
create arrays
create typed arrays
create typed arrays in typed array
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0
Browser/OS:
Firefox 128 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
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
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
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: 1. **Push to: array**: This approach creates an empty array (`const a = []`) and then pushes elements onto it using the `push()` method. 2. **Create typed arrays**: This approach creates a Float32Array object with 10,000 elements and then pushes elements onto it using the `push()` method. 3. **Create typed arrays in typed array**: This approach creates a new Float32Array object with 10,000 elements and then assigns a new Float32Array object to each element of the original array. **Options Compared** The benchmark compares the performance of three approaches: * Pushing data onto an existing array * Creating a new typed array and pushing data onto it * Creating a new typed array and assigning a new typed array to each element of an existing array **Pros and Cons of Each Approach** 1. **Push to: array** * Pros: + Easy to implement + Works well for small datasets * Cons: + Can be slower due to the overhead of creating a new array on each push operation 2. **Create typed arrays** * Pros: + Can be faster than pushing data onto an existing array, as it avoids the overhead of array creation on each push operation * Cons: + Requires more memory upfront, as the entire typed array needs to be allocated in memory 3. **Create typed arrays in typed array** * Pros: + Combines the benefits of both approaches: reduces the overhead of array creation and avoids the need for a large contiguous block of memory upfront * Cons: + Can be more complex to implement, as it requires creating multiple typed arrays and assigning them to each element of an existing array **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()`).
Related benchmarks:
Spread vs Push when copying array
Large arrays spread vs push
Large arrays spread vs push v2
Array.push vs Spread operator
Spread vs Push when adding into array
Comments
Confirm delete:
Do you really want to delete benchmark?