Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Deserialize - Dataview vs Custom
(version: 0)
Comparing performance of:
Dataview vs Custom
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
function generateDataset(limit) { let result = new Uint8Array(limit); for (let i = 0; i < limit; i++) { result[i] = i; } return result; } function decodeFrom(src, ptr) { return ((src[ptr] << 24) | (src[ptr + 1] << 16) | (src[ptr + 2] << 8) | src[ptr + 3]) >>> 0; } var time = 200; var limit = 1000000; var dataset = generateDataset(limit); var view = new DataView(dataset.buffer);
Tests:
Dataview
for (let i = 0; i < limit; i += 4) { view.getUint32(i) }
Custom
for (let i = 0; i < limit; i += 4) { decodeFrom(dataset, i) }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Dataview
Custom
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
Browser/OS:
Chrome 127 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Dataview
32.6 Ops/sec
Custom
21.7 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark definition and test cases to understand what is being tested. **Benchmark Definition** The benchmark definition consists of two separate test cases: 1. **Dataview**: This test case uses the `DataView` API to access 32-bit unsigned integers in a Uint8Array buffer. The benchmark repeatedly calls `view.getUint32(i)` for a specific loop variable `i`. 2. **Custom**: This test case uses a custom function called `decodeFrom` to decode 32-bit unsigned integers from a Uint8Array buffer. The benchmark repeatedly calls `decodeFrom(dataset, i)` for the same loop variable `i`. **Options Compared** The two options being compared are: * Using the `DataView` API * Implementing a custom decoding function **Pros and Cons** ### **DataView API** Pros: * Native implementation, optimized for performance * Standardized API, widely supported by browsers * Easy to use and understand Cons: * Limited control over the underlying buffer management * May not work as expected with certain data types or formats ### **Custom Decoding Function** Pros: * Full control over the decoding process * Can handle complex data types or formats * May provide better performance for specific use cases Cons: * More complex and harder to understand, especially for non-experts * Requires manual management of buffer pointers and sizes * May not be supported by all browsers **Library** In both test cases, the `DataView` API is used. The `DataView` is a built-in JavaScript object that provides a way to interact with typed arrays and views in a more intuitive way. The purpose of `DataView` is to provide an easy-to-use interface for accessing and manipulating data stored in buffers or views. It allows developers to access individual elements, perform arithmetic operations, and more without having to manually manage the underlying buffer pointers. **Special JS Feature** There is no special JavaScript feature being used in this benchmark. The `DataView` API is a standardized feature that has been part of JavaScript for several years. **Alternatives** If you're looking for alternatives to the `DataView` API, you may consider using other libraries or APIs that provide similar functionality. Some examples include: * `Buffer`: A Node.js library that provides a way to work with buffers in JavaScript. * `TypedArrays`: A family of built-in JavaScript arrays that provide typed access to data stored in buffers or views. * Custom implementation: You can also implement your own buffer management and decoding logic using JavaScript, but this would likely require more code and expertise. In summary, the benchmark is testing two options for accessing and manipulating data in a Uint8Array buffer: using the `DataView` API versus implementing a custom decoding function. The choice between these two options depends on your specific requirements, performance needs, and familiarity with JavaScript APIs.
Related benchmarks:
Dataview vs Uint8Array - read byted
DataView vs Uint8Array by bytes
copy ArrayBuffer: DataView vs Uint8Array.set vs Float64Array.set vs by bytes (2)
uint8array vs dataview extract
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?