Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
typedarray vs dataview
(version: 0)
Comparing performance of:
blaaaa vs dataview
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function readAs(buf, Type, offset, count) { count = count === undefined || count === 0 ? 1 : count; const sub = buf.slice(offset, offset + Type.BYTES_PER_ELEMENT * count); const r = new Type(sub); if (count === undefined || count === 1) return r[0]; const ret = []; for (let i = 0; i < count; i++) { ret.push(r[i]); } return ret; }
Tests:
blaaaa
(() => { const arraybuffer = new ArrayBuffer(1000000); const o = {}; o.pointsOffset = readAs(arraybuffer, Uint32Array, 96); // offset to point data o.pointsFormatId = readAs(arraybuffer, Uint8Array, 104) & 0b111111; o.pointsStructSize = readAs(arraybuffer, Uint16Array, 105); // point data record length o.pointsCount = readAs(arraybuffer, Uint32Array, 107); // number of point records let start = 32 * 3 + 35; o.scale = readAs(arraybuffer, Float64Array, start, 3); // [scale X, scale Y, scale Z] start += 24; o.offset = readAs(arraybuffer, Float64Array, start, 3); // [offset X, offset Y, offset Z] start += 24; const bounds = readAs(arraybuffer, Float64Array, start, 6); o.maxs = [bounds[0], bounds[2], bounds[4]]; // max X, max Y, max Z o.mins = [bounds[1], bounds[3], bounds[5]]; // min X, min Y, min Z })()
dataview
(() => { const arraybuffer = new ArrayBuffer(1000000); const o = {}; const dv = new DataView(arraybuffer); o.pointsOffset = dv.getUint32(96, true); // offset to point data o.pointsFormatId = dv.getUint8(104, true) & 0b111111; o.pointsStructSize = dv.getUint16(105, true); // point data record length o.extraBytes = 0; o.pointsCount = dv.getUint32(107, true); let start = 32 * 3 + 35; o.scale = [dv.getFloat64(start, true), dv.getFloat64(start + 8, true), dv.getFloat64(start + 16, true)]; // [scale X, scale Y, scale Z] start += 24; o.offset = [dv.getFloat64(start, true), dv.getFloat64(start + 8, true), dv.getFloat64(start + 16, true)]; // [scale X, scale Y, scale Z] start += 24; const bounds = [ dv.getFloat64(start, true), dv.getFloat64(start + 8, true), dv.getFloat64(start + 16, true), dv.getFloat64(start + 24, true), dv.getFloat64(start + 32, true), dv.getFloat64(start + 40, true), ]; // [scale X, scale Y, scale Z]; o.maxs = [bounds[0], bounds[2], bounds[4]]; // max X, max Y, max Z o.mins = [bounds[1], bounds[3], bounds[5]]; // min X, min Y, min Z })()
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
blaaaa
dataview
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/136.0.0.0 Safari/537.36
Browser/OS:
Chrome 136 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
blaaaa
8911.8 Ops/sec
dataview
11990.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what's being tested. **Benchmark Definition** The benchmark measures the performance of two approaches to read data from an `ArrayBuffer`: 1. Using `TypedArray` (specifically, `Uint32Array`, `Uint8Array`, and `Float64Array`) through a custom `readAs` function. 2. Using a `DataView` object. **Options being compared** The benchmark compares the performance of these two approaches on a single test case: * Reading data from an `ArrayBuffer` to extract various field values (e.g., points offset, format ID, struct size, scale, and bounds). * The same test case is executed twice, once using `TypedArray` and once using `DataView`. **Pros and Cons** **TypedArray approach:** Pros: * Can be used to create typed arrays from the `ArrayBuffer`, which can provide better memory safety and performance. * Might be more efficient for smaller buffer sizes. Cons: * Requires creating a typed array object, which can allocate additional memory. * The custom `readAs` function is needed to read data from the `ArrayBuffer`. **DataView approach:** Pros: * Allows direct access to specific fields in the `ArrayBuffer`, without allocating additional memory. * Can be more efficient for larger buffer sizes. Cons: * Requires creating a `DataView` object, which can allocate additional memory. * Might not provide the same level of memory safety as typed arrays. **Library usage** In both test cases, no external libraries are used. The custom `readAs` function is implemented to read data from the `ArrayBuffer`, and the `DataView` object is used directly. **Special JS feature or syntax** There are no special JS features or syntax used in this benchmark. The focus is on comparing the performance of two different approaches to reading data from an `ArrayBuffer`. **Alternatives** Other alternatives to compare might include: * Using a library like `uint8array` or `typedarray-browserify` to create typed arrays. * Using a more modern approach, such as using WebAssembly (WASM) to read data from an `ArrayBuffer`. * Comparing the performance of other buffer management techniques, such as using buffers with `buffer.alloc()`. Keep in mind that the specific alternatives will depend on the requirements and goals of the benchmark.
Related benchmarks:
JS number to UInt8Array 64-bit little endian
JS number to UInt8Array 64-bit little endian 2
DataView or BitTwiddling for Reads
Binary to boolean with DataView: readUint8() with for loop vs. slice() with map()
Binary to boolean with DataView: readUint8() with for loop vs. slice() with map() vs. slice() with Array.from()
Comments
Confirm delete:
Do you really want to delete benchmark?