Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Push to: array vs float32array performance test 3
(version: 0)
Comparing performance of:
arrays vs typed arrays
Created:
one year ago
by:
Registered User
Jump to the latest result
Tests:
arrays
const a = []; for (let i = 0; i < 10_000; i++) { a.push(i); }
typed arrays
const a = new Float32Array(10_000); for (let i = 0; i < 10_000; i++) { a[i] = i; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
arrays
typed arrays
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:135.0) Gecko/20100101 Firefox/135.0
Browser/OS:
Firefox 135 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
arrays
12697.0 Ops/sec
typed arrays
35996.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided JSON data and explain what's being tested, compared, and the pros/cons of each approach. **Benchmark Definition** The benchmark is designed to compare the performance of two approaches: 1. Pushing elements onto an array (JavaScript built-in Array type) 2. Pushing elements onto a typed array (Float32Array in this case) **What are we testing?** We're testing how long it takes for each approach to push 10,000 elements into their respective data structures. **Options compared** The two options being compared are: 1. **Arrays**: JavaScript's built-in Array type. 2. **Typed Arrays**: Float32Array, which is a typed array that stores 32-bit floating-point numbers. **Pros and Cons of each approach:** **Arrays:** Pros: * Easy to use and implement * Widely supported by most browsers Cons: * Performance can be slower compared to typed arrays due to the overhead of storing and managing primitive values. * Can lead to memory issues if not handled properly. **Typed Arrays (Float32Array):** Pros: * Provides better performance compared to arrays, especially for numerical computations. * Reduces memory usage by storing only the actual data. Cons: * More complex to use and implement due to the need to specify the data type and size of the array. * Not all browsers support typed arrays, although most modern ones do. **Library Used** In this case, no specific library is used. The benchmark defines a custom script that creates and populates the arrays and typed arrays. **Special JavaScript Feature or Syntax** There are no special JavaScript features or syntaxes being tested in this benchmark. It's focused on comparing the performance of two different data structures. **Other Alternatives** If you're interested in exploring other alternatives, here are a few options: * **Uint8Array**: An unsigned 8-bit integer typed array that can be used for storing binary data. * **Int8Array**: A signed 8-bit integer typed array that can be used for storing small integers. * **BigInt**: A JavaScript built-in type that supports arbitrary-precision integers, useful for dealing with very large numbers. These alternatives offer different trade-offs between performance, memory usage, and complexity.
Related benchmarks:
Array spread vs. push performance
Push to array, vs ES6 Spread.
Spread vs Push when copying array
Array .push() vs .unshift() vs spread
Spread vs Push when adding into array
Comments
Confirm delete:
Do you really want to delete benchmark?