Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
JSON.parse vs dataview
(version: 0)
Comparing performance of:
JSON vs dataview
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var intObj = [] function getRandomArbitrary(min, max) { return Math.random() * (max - min) + min; } for(let i = 0; i < 250000; i++) { intObj.push(getRandomArbitrary(0, 1000000)); } var buffer = new ArrayBuffer(4 + (intObj.length * 4)); var dv = new DataView(buffer); dv.setInt32(0, intObj.length); for(let i = 0; i < intObj.length; i++) { dv.setInt32(4 + (i * 4), intObj[i]); } var stringy = JSON.stringify(intObj);
Tests:
JSON
let parsed = JSON.parse(stringy); let a; a = parsed;
dataview
let newView = new DataView(dv.buffer); let offset = 0; let count = newView.getInt32(offset); offset += 4; for(let i = 0; i < count; i++) { let value = newView.getInt32(offset); offset += 4; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
JSON
dataview
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
4 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:146.0) Gecko/20100101 Firefox/146.0
Browser/OS:
Firefox 146 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
JSON
94.0 Ops/sec
dataview
13917.7 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and its test cases. **Benchmark Overview** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks. The provided benchmark compares two approaches: `JSON.parse()` and `DataView` (also known as `dataview`). Both methods are used to parse an array of integers, but they differ in how they represent the data. **Benchmark Definition JSON** The benchmark definition JSON contains: * `"Name"`: The name of the benchmark, which is "JSON.parse vs dataview". * `"Script Preparation Code"`: A JavaScript code snippet that prepares the test data. This code creates an array `intObj` with 250,000 random integers and converts it to a string using `JSON.stringify()`. It also creates a new `ArrayBuffer` and a `DataView` object to store the parsed integer values. * `"Html Preparation Code"`: An empty string, indicating that no HTML preparation code is required. **Individual Test Cases** There are two test cases: 1. **"JSON"`** * The benchmark definition contains the line `let parsed = JSON.parse(stringy);`. This line uses `JSON.parse()` to parse the converted integer array. * There is no additional code that modifies or manipulates the parsed data. 2. **"dataview"`** * The benchmark definition contains a block of code that creates a new `DataView` object, reads the integer values from the buffer, and assigns them to a variable `value`. * This code appears to be using the `DataView` API to access the parsed data without parsing it again. **Pros and Cons** * **JSON.parse()**: + Pros: Simple, widely supported, and easy to understand. + Cons: May involve additional overhead due to string manipulation and parsing. * **dataview (DataView)**: + Pros: Can potentially be faster since it avoids the overhead of parsing and string manipulation. + Cons: Requires understanding of the `DataView` API and its limitations. **Library/Technology Used** In this benchmark, the following libraries or technologies are used: * `JSON`: A built-in JavaScript object that provides methods for working with JSON data. * `DataView`: A browser API that allows reading and writing binary data in a typed array. **Special JS Feature/Syntax** There is no special JavaScript feature or syntax mentioned in this benchmark. The focus is on the comparison between two approaches to parse an integer array. **Alternatives** If you were to modify this benchmark, some alternatives could be: * Using `BigInt` instead of integers: This would allow for larger integers and potentially different performance characteristics. * Adding more test cases: For example, testing with larger or smaller arrays, or using different data types (e.g., floats). * Using different browsers or environments: This would help to isolate browser-specific issues and provide a more comprehensive understanding of the benchmark's behavior.
Related benchmarks:
ArrayBuffer vs JSON serialization ---- v2
JSON.parse vs dataview vs typedarray
json stringify vs array tostring large obj
json stringify vs array tostring large obj random
Comments
Confirm delete:
Do you really want to delete benchmark?