Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
DataView vs Uint8Array (read bytes)
(version: 0)
Comparing performance of:
read bytes (DataView) vs read bytes (Uint8Array)
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var size = 0xFF; var buf = new ArrayBuffer(size); var view = new DataView(buf); var byte = new Uint8Array(buf); var test_sum = 0;
Tests:
read bytes (DataView)
let sum = 0; for (let i=0; i < size; i++) { let val = view.getUint8(i); sum += val; sum |= val; sum ^= val; } test_sum = sum;
read bytes (Uint8Array)
let sum = 0; for (let i=0; i < size; i++) { let val = byte[i]; sum += val; sum |= val; sum ^= val; } test_sum = sum;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
read bytes (DataView)
read bytes (Uint8Array)
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 17_2_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/122.2 Mobile/15E148 Safari/605.1.15
Browser/OS:
Mobile Safari 17 on iOS 17.2.1
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
read bytes (DataView)
70738.9 Ops/sec
read bytes (Uint8Array)
67769.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript benchmarks! **What is tested:** The provided JSON represents a benchmark test case for comparing two approaches to read bytes from an array buffer: `DataView` and `Uint8Array`. The test checks which approach is faster. **Options compared:** 1. **DataView**: A typed array that wraps around a mutable ArrayBuffer, allowing direct access to the underlying buffer's data. 2. **Uint8Array**: An untyped array for holding 8-bit unsigned integer values. **Pros and Cons of each approach:** * **DataView**: + Pros: - Provides direct access to the underlying buffer's data, making it potentially faster. - Offers typed array functionality, which can improve performance. + Cons: - Requires an ArrayBuffer as its backing store, which might incur additional overhead. - Can be less intuitive for some developers due to its abstracted nature. * **Uint8Array**: + Pros: - Is a widely supported and well-understood data type in JavaScript. - Does not require an additional buffer object as its backing store, reducing overhead. + Cons: - May incur slower performance due to the indirect access pattern. **Library usage:** Neither `DataView` nor `Uint8Array` is a separate library; they are built-in data types in JavaScript. **Special JS feature or syntax:** The test uses bitwise operators (`|=` and `^=`) as part of its benchmarking logic. These operators have specific meanings: + `|=` performs a bitwise OR assignment. + `^=` performs a bitwise XOR assignment. These operators are used to calculate the sum of the bytes read from the buffer, taking advantage of the properties of bitwise operations for integer arithmetic. **Other alternatives:** If you want to explore alternative approaches or libraries for reading bytes from an array buffer, consider: * **Canvas**: While not directly related to reading bytes from an array buffer, Canvas can provide a similar abstraction layer for graphics and image data manipulation. * **WebAssembly**: If you're interested in exploring WebAssembly's ability to manage binary data, it provides more low-level control over data representation. Keep in mind that these alternatives might not directly compare to the specific use case of `DataView` or `Uint8Array`. **Benchmark preparation code:** The script prepares a simple test environment: 1. Allocates an ArrayBuffer with a size of 0xFF (255). 2. Creates a DataView object from this buffer. 3. Creates a Uint8Array object from the same buffer. These objects will serve as the input for our benchmarking loop, which we'll see in the next step.
Related benchmarks:
Dataview vs Uint8Array - read byted
DataView vs Uint8Array by bytes vs Native Array
DataView or BitTwiddling for Reads
uint8array vs dataview extract
Comments
Confirm delete:
Do you really want to delete benchmark?