Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
read write ArrayBuffer: DataView vs Float64Array.set v2
(version: 0)
Comparing performance of:
DataView vs Float64Array vs Float32Array vs DataView 32
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var size = 50000; var buf = new ArrayBuffer(size*8); var view = new DataView(buf); var buf2 = new ArrayBuffer(size*4); var view2 = new DataView(buf2); var data = new Float64Array(size); var data2 = new Float32Array(size);
Tests:
DataView
for (let i=0; i < size; i++) { view.setFloat64(i*8, 992.2258); } for (let i=0; i < size; i++) { const res = view.getFloat64(i*8); }
Float64Array
for (let i=0; i < size; i++) { data[i] = 992.2258; } for (let i=0; i < size; i++) { const res = data[i]; }
Float32Array
for (let i=0; i < size; i++) { data[i] = 992.2258; } for (let i=0; i < size; i++) { const res = data[i]; }
DataView 32
for (let i=0; i < size; i++) { view2.setFloat32(i*4, 992.2258); } for (let i=0; i < size; i++) { const res = view2.getFloat32(i*4); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
DataView
Float64Array
Float32Array
DataView 32
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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Browser/OS:
Chrome 126 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
DataView
172.5 Ops/sec
Float64Array
174.5 Ops/sec
Float32Array
174.2 Ops/sec
DataView 32
172.7 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested. **Benchmark Overview** The benchmark compares the performance of four approaches: 1. `Float64Array.set` (using `DataView`) 2. Direct assignment to an array (`Float64Array` or `Float32Array`) 3. Using a `DataView` with 32-bit floating-point numbers (i.e., `Float32Array`) **What's being tested** The benchmark is testing the performance of writing and reading data from arrays using different approaches. 1. The first test case uses `DataView.set` to write data to an array, and then reads it back using `DataView.getFloat64`. 2. The second test case directly assigns values to a `Float64Array`, which becomes the source for the read operation. 3. The third test case is similar to the second one but uses a `DataView` with 32-bit floating-point numbers (`Float32Array`) instead of 64-bit. **Options comparison** Here's a brief overview of each option and their pros and cons: 1. **Direct assignment**: This approach is straightforward and easy to understand. However, it may incur additional overhead due to the language's garbage collection mechanism. * Pros: Easy to implement, no additional libraries required. * Cons: May incur performance overhead due to garbage collection. 2. **DataView.set** (using `DataView`): This approach uses a `DataView` object to write data to an array. It provides more control over memory management and can be faster than direct assignment. * Pros: Can be faster, provides better memory management control. * Cons: Requires understanding of `DataView` and its usage. 3. **Direct assignment (32-bit float)**: This approach uses a `Float32Array`, which reduces memory usage compared to using a `Float64Array`. However, it may incur additional overhead due to the difference in data types. * Pros: Reduced memory usage, potentially faster due to reduced memory access patterns. * Cons: May incur performance overhead due to type conversion. **Library** In this benchmark, no explicit library is mentioned. However, it's worth noting that `DataView` and array operations are part of the standard JavaScript API. **Special JS feature or syntax** There's no special JavaScript feature or syntax being used in this benchmark. The tests only involve basic arithmetic operations and array manipulation. **Alternative approaches** Other alternatives to consider when working with arrays and memory management include: * Using typed arrays (e.g., `Int32Array`, `Uint8Array`) for specific use cases. * Utilizing WebAssembly (WASM) for performance-critical code that requires direct memory access. * Employing libraries like WebAssembly's `wasm-bindgen` or JavaScript libraries like `fastify` or `express` for high-performance networking. In summary, this benchmark compares the performance of different approaches to writing and reading data from arrays using JavaScript. The results can help developers understand the trade-offs between direct assignment, `DataView`, and 32-bit floating-point numbers when working with memory management in JavaScript.
Related benchmarks:
copy ArrayBuffer: DataView vs Uint8Array.set vs Float64Array.set vs by bytes
read write ArrayBuffer: DataView vs Float64Array.set
Float32Array vs DataView 2022
copy ArrayBuffer: DataView vs Uint8Array.set vs Float64Array.set vs by bytes (2)
Comments
Confirm delete:
Do you really want to delete benchmark?