Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
JSON.parse vs dataview vs typedarray
(version: 0)
Comparing performance of:
JSON vs TypedArray vs dataview
Created:
3 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var intObj = {alpha:12345678,beta:12345678,charlie:12345678,delta:12345678,foxtrot:12345678} var typedArray = new Int32Array(12345678,12345678,12345678,12345678,12345678) var buffer = new ArrayBuffer(20) var dv = new DataView(buffer) dv.setInt32(0,12345678) dv.setInt32(4,12345678) dv.setInt32(8,12345678) dv.setInt32(12,12345678) dv.setInt32(16,12345678)
Tests:
JSON
let stringy = JSON.stringify(intObj); let parsed = JSON.parse(stringy); let a; a = parsed;
TypedArray
let newBuffer = typedArray.buffer let parsedBuffer = new Int32Array(newBuffer) let b; b = parsedBuffer;
dataview
let dvBuffer = dv.buffer let newView = new DataView(dvBuffer) let c; c = newView;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
JSON
TypedArray
dataview
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
4 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:146.0) Gecko/20100101 Firefox/146.0
Browser/OS:
Firefox 146 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
JSON
640840.8 Ops/sec
TypedArray
5418229.0 Ops/sec
dataview
5938742.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the explanation of the benchmark. **Benchmark Overview** The benchmark compares three approaches to represent and manipulate integer data in JavaScript: 1. **JSON**: Using `JSON.stringify()` and `JSON.parse()` to convert an object to a string and back to an object, respectively. 2. **TypedArray**: Using a typed array (`Int32Array`) to store integer values. 3. **DataView**: Using a `DataView` object to view and manipulate the memory of a buffer. **Options Compared** The benchmark compares these three approaches in terms of their performance (measured by executions per second) on a Chrome browser running on a Linux desktop. **Pros and Cons of Each Approach** 1. **JSON**: * Pros: Easy to use, widely supported, and platform-agnostic. * Cons: May incur overhead due to string manipulation, can lead to security vulnerabilities if not properly sanitized, and may not perform well for large datasets. 2. **TypedArray**: * Pros: Provides direct access to memory, efficient for large datasets, and allows for fine-grained control over data types. * Cons: Can be error-prone if not used correctly, requires manual management of buffer allocation and deallocation, and may have performance implications due to the overhead of typed array operations. 3. **DataView**: * Pros: Offers a convenient abstraction over memory views, easy to use, and can provide good performance for certain use cases. * Cons: May not be as efficient as typed arrays for large datasets, requires manual management of buffer allocation and deallocation, and can lead to security vulnerabilities if not properly sanitized. **Library and Its Purpose** In the benchmark, `DataView` is a built-in JavaScript object that allows you to view and manipulate the memory of a buffer. It provides an efficient way to access binary data in a platform-agnostic manner. **Special JS Feature or Syntax** There are no special features or syntaxes being tested in this benchmark. The focus is on comparing three common approaches to represent and manipulate integer data in JavaScript. **Other Alternatives** Some other alternatives for representing and manipulating integer data in JavaScript include: 1. **BigInt**: Introduced in ECMAScript 2020, `BigInt` provides a way to work with integers that can be arbitrarily large. 2. **ArrayBuffers**: Similar to typed arrays, array buffers provide direct access to memory and are efficient for large datasets. In summary, this benchmark compares three approaches to represent and manipulate integer data in JavaScript: JSON, TypedArray, and DataView. Each approach has its pros and cons, and the choice of which one to use depends on the specific requirements and constraints of the project.
Related benchmarks:
substr vs JSON.parse
uint8Array MsgPack - json stringify vs string tostring on array
test json vs omit
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?