Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Buffer Access 4 - PK
(version: 0)
Comparing performance of:
DataView AoS vs DataView byte-aligned AoS vs TypedArray byte-aligned AoS vs TypeArray SoA
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var bench1buffer; var bench2buffer; var bench3buffer; var size = 1_000_000; { const stride = 18; bench1buffer = new ArrayBuffer(stride * size); /* 0 u16 id 2 f64 x 10 f64 y */ for (let i = 0; i < size; i++) { const struct = new DataView(bench1buffer, i * stride, stride); struct.setUint16(0, i, true); struct.setFloat64(2, i, true); struct.setFloat64(10, i * 2, true); } } { const stride = 24; bench2buffer = new ArrayBuffer(stride * size); /* 0 u16 id 8 f64 x 16 f64 y */ for (let i = 0; i < size; i++) { const struct = new DataView(bench2buffer, i * stride, stride); struct.setUint16(0, i, true); struct.setFloat64(8, i, true); struct.setFloat64(16, i * 2, true); } } { bench3buffer = { id: new Uint16Array(size), x: new Float64Array(size), y: new Float64Array(size), }; for (let i = 0; i < size; i++) { bench3buffer.id[i] = i; bench3buffer.x[i] = i; bench3buffer.y[i] = i * 2; } }
Tests:
DataView AoS
const stride = 18; /* 0 u16 id 2 f64 x 10 f64 y */ const view = new DataView(bench1buffer); let sum = 0; for (let i = 0; i < size; i++) { const offset = i * stride; const id = view.getUint16(offset, true); const x = view.getFloat64(offset + 2, true); const y = view.getFloat64(offset + 10, true); sum += id + x * y; } console.log(1, sum);
DataView byte-aligned AoS
const stride = 24; /* 0 u16 id 8 f64 x 16 f64 y */ const view = new DataView(bench2buffer); let sum = 0; for (let i = 0; i < size; i++) { const offset = i * stride; const id = view.getUint16(offset, true); const x = view.getFloat64(offset + 8, true); const y = view.getFloat64(offset + 16, true); sum += id + x * y; } console.log(2, sum);
TypedArray byte-aligned AoS
const stride = 24; /* 0 u16 id 8 f64 x 16 f64 y */ const f64s = new Float64Array(bench2buffer); const u16s = new Uint16Array(bench2buffer); let sum = 0; for (let i = 0; i < size; i++) { const offset = i * stride; const id = u16s[offset / 2]; const x = f64s[offset / 8 + 1]; const y = f64s[offset / 8 + 2]; sum += id + x * y; } console.log(3, sum);
TypeArray SoA
let sum = 0; const idbuf = bench3buffer.id; const xbuf = bench3buffer.x; const ybuf = bench3buffer.y; for (let i = 0; i < size; i++) { const id = idbuf[i]; const x = xbuf[i]; const y = ybuf[i]; sum += id + x * y; } console.log(4, sum);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
DataView AoS
DataView byte-aligned AoS
TypedArray byte-aligned AoS
TypeArray SoA
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Overview** The provided JSON represents a JavaScript microbenchmarking test suite, specifically designed to measure the performance of various approaches for accessing and manipulating structured data in JavaScript. **Benchmark Definition** The benchmark definition consists of three main test cases: 1. **DataView AoS (Array of Structures)**: This approach stores each structure as an independent array element, where each element is a DataView object that represents a single row in the table. 2. **DataView byte-aligned AoS**: Similar to the previous approach but with added padding between structures to ensure proper alignment. 3. **TypedArray byte-aligned AoS**: This method uses typed arrays (Float64Array and Uint16Array) instead of DataViews, providing a more efficient way to store and access structured data. **Comparison** The main differences between these approaches are: * Storage overhead: DataView objects have additional metadata that needs to be accessed when storing and retrieving data. * Access patterns: In AoS implementations (DataView and TypedArray), accessing individual fields requires calculating the offset within each row, which can lead to slower performance for small structures. Byte-aligned AoS mitigates this issue by padding structures with zeros. **Pros and Cons** | Approach | Pros | Cons | | :-------- | :----- | :------ | | **DataView AoS** | Less storage overhead, straightforward implementation | Potential access issues due to metadata | | **DataView byte-aligned AoS** | Better alignment, reduced access overhead for small structures | Increased storage overhead due to padding | | **TypedArray byte-aligned AoS** | Most efficient in terms of storage and access patterns, with minimal overhead | Requires explicit handling of data types | **Performance** According to the latest benchmark results, the TypedArray approach outperforms DataView AoS by about 50% (on this specific test), while DataView byte-aligned AoS is slightly slower than its AoS counterpart due to increased storage overhead. The exact performance differences may vary depending on the specific use case and hardware. In summary, the choice of approach depends on the trade-offs between storage efficiency, access patterns, and implementation complexity. For most use cases, TypedArray byte-aligned AoS seems to be the most efficient solution, while DataView approaches are better suited for scenarios with minimal structure size or where simplicity is prioritized over performance.
Related benchmarks:
Buffer Access 2
Buffer Access 2 - const arrays
Buffer Access 3
Buffer Access 4
Comments
Confirm delete:
Do you really want to delete benchmark?