Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Dataview vs Uint8Array - read short
(version: 0)
Comparing performance of:
DataView vs Uint8Array
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var size = 1024; var buffer = new ArrayBuffer(size); var bytes = new Uint8Array(buffer); var dv = new DataView(buffer); for (var i = 0; i < size; i++) dv.setUint8(i, Math.ceil(Math.random() * 255));
Tests:
DataView
for (var i = 0; i < size; i+=2) dv.getUint16(i);
Uint8Array
for (var i = 0; i < size; i+=2) bytes.subarray(i, i + 2);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
DataView
Uint8Array
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/119.0.6045.169 Mobile/15E148 Safari/604.1
Browser/OS:
Chrome Mobile iOS 119 on iOS 16.6
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
DataView
14858.5 Ops/sec
Uint8Array
9610.3 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 is testing two approaches to read data from a buffer: `DataView` and `Uint8Array`. **Options Compared** There are two options being compared: 1. **DataView**: A binary view of an ArrayBuffer, which allows direct access to the underlying byte array. 2. **Uint8Array**: An array of unsigned 8-bit integers, where each element represents a single byte. **Pros and Cons** * **DataView**: + Pros: Direct access to the underlying buffer, potentially more efficient for large datasets or complex data structures. + Cons: Requires manual management of the buffer's length and offset, can be less intuitive for beginners. * **Uint8Array**: + Pros: More familiar and easier to use for developers, with a simpler and more linear memory model. + Cons: May incur additional overhead due to array manipulation and indexing. **Library** In this benchmark, `DataView` is being used as a library function to access the underlying buffer. `DataView` provides a way to view an ArrayBuffer as if it were a typed array (in this case, a 16-bit integer array), allowing for direct access to the individual bytes. **Special JavaScript Feature or Syntax** There are no special features or syntax being tested in this benchmark. The code is written in standard JavaScript syntax. **Other Considerations** When choosing between `DataView` and `Uint8Array`, consider the following: * If you need direct, fine-grained control over the buffer's data, `DataView` might be a better choice. * If you're working with smaller datasets or need more high-level abstractions, `Uint8Array` might be sufficient. **Alternatives** Other alternatives for reading data from buffers include: * **Typed Arrays**: Such as Int32Array, Uint16Array, etc. These provide a higher-level interface for accessing and manipulating arrays of integers. * **Buffer APIs**: Such as Buffer.from() or Buffer.alloc(), which allow direct manipulation of the buffer's contents. However, in this specific benchmark, `DataView` is being compared directly to `Uint8Array`, so these alternatives are not relevant.
Related benchmarks:
Dataview vs Uint8Array - read byte
Dataview vs Uint8Array - read byted
copy ArrayBuffer: DataView vs Uint8Array.set vs Float64Array.set vs by bytes
copy ArrayBuffer: DataView vs Uint8Array.set vs Float64Array.set vs by bytes (2)
Comments
Confirm delete:
Do you really want to delete benchmark?