Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
TypedArray performance
(version: 0)
Comparing performance of:
Array vs Float32Array vs Float64Array
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var n = 10000; var range = 1000000; var a = [...Array(n)].map(_ => Math.random(range)); var a32 = new Float32Array(a); var a64 = new Float64Array(a);
Tests:
Array
for (let i = 0; i < n; i++) { a[i] = a[i] / 2; }
Float32Array
for (let i = 0; i < n; i++) { a32[i] = a32[i] / 2; }
Float64Array
for (let i = 0; i < n; i++) { a64[i] = a64[i] / 2; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Array
Float32Array
Float64Array
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:132.0) Gecko/20100101 Firefox/132.0
Browser/OS:
Firefox 132 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array
69224.7 Ops/sec
Float32Array
137563.3 Ops/sec
Float64Array
137523.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to explain the benchmark and its results. **Benchmark Overview** The benchmark measures the performance of three types of TypedArray operations: Array, Float32Array, and Float64Array. A TypedArray is a data structure in JavaScript that provides efficient access to numeric data. **Options Compared** In this benchmark, two options are compared: 1. **Array**: This option uses the native JavaScript `Array` object. 2. **Float32Array / Float64Array**: These options use the corresponding typed array classes (`Float32Array` and `Float64Array`) from the JavaScript standard library. **Pros and Cons** Here's a brief summary of the pros and cons of each approach: * **Array**: * Pros: Native JavaScript implementation, likely to be optimized for performance. * Cons: May not take advantage of native TypedArray optimizations. * **Float32Array / Float64Array**: * Pros: Can leverage native TypedArray optimizations and may provide better performance due to lower memory overhead. * Cons: Requires explicit creation using the typed array classes, which can introduce additional overhead. **Library Used** The benchmark uses the following libraries: * None (native JavaScript implementation). **Special JS Feature or Syntax** This benchmark does not use any special JavaScript features or syntax. However, it relies on the TypedArray classes, which are a feature introduced in ECMAScript 2015 (ES6). **Benchmark Preparation Code Explanation** The preparation code initializes an array `a` with random values between 0 and `range`, then creates two TypedArrays: `a32` (Float32Array) and `a64` (Float64Array). The benchmark definition code is a simple loop that performs the same operation on each element of these arrays. **Test Case Explanation** Each test case is identical, with only the array type changed. This allows for a fair comparison between the Array and TypedArray approaches. **Other Alternatives** If you were to consider alternative implementations or optimizations for this benchmark: * Using native WebAssembly (WASM) types might provide better performance due to their low-level nature. * Compiling JavaScript to native machine code using tools like V8 or Webpack's optimization plugins could further improve performance. However, these alternatives may introduce additional complexity and are likely only beneficial if you're targeting a specific platform or have specific requirements that aren't addressed by the standard library implementations.
Related benchmarks:
array vs Float64Array write performance
array vs float32array without conversion 2
array vs float64 for io and slice
array vs float64 for io and slice (fixed)
Comments
Confirm delete:
Do you really want to delete benchmark?