Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
ArrayBuffer vs JSON serialization ---- v2
(version: 0)
Comparing performance of:
JSON serialization vs ArrayBuffer serialization
Created:
3 years ago
by:
Guest
Jump to the latest result
Tests:
JSON serialization
const arr = Array.from({ length: 5000 }).map(() => Math.random()); const serialized = JSON.stringify(arr); const deserialized = JSON.parse(serialized); const serializedAgain = JSON.stringify(deserialized);
ArrayBuffer serialization
const arr = Array.from({ length: 5000 }).map(() => Math.random()); const buffer = new ArrayBuffer(arr.length * 4); const view = new DataView(buffer); for (let i = 0; i<buffer.byteLength; i+=4){ view.setFloat32(arr[i]); } const view2 = new DataView(buffer);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
JSON serialization
ArrayBuffer serialization
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
JSON serialization
1117.6 Ops/sec
ArrayBuffer serialization
5453.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and its test cases. **What is being tested?** The two test cases compare how different browsers serialize JavaScript arrays using either `ArrayBuffer` or JSON serialization. **Options compared:** 1. **JSON serialization**: The browser converts the array into a string format using `JSON.stringify()` and then deserializes it back to an array using `JSON.parse()`. 2. **ArrayBuffer serialization**: The browser creates an `ArrayBuffer` instance, stores the array data in it using a `DataView`, and then serializes the buffer. **Pros and cons of each approach:** 1. **JSON serialization:** * Pros: + Widely supported across browsers. + Human-readable format. * Cons: + May not be as efficient for large datasets. + Can lead to larger serialized data sizes. 2. **ArrayBuffer serialization:** * Pros: + More efficient for large datasets. + Can result in smaller serialized data sizes. * Cons: + Not all browsers support `ArrayBuffer` and `DataView`. + Requires manual handling of the `DataView` object. **Other considerations:** 1. **Browser support**: Both approaches rely on browser-specific features, which may not be compatible across all browsers. 2. **Performance differences**: The test results indicate that ArrayBuffer serialization is faster than JSON serialization in this specific benchmark. **Library usage:** In the provided benchmark code, there is no explicit library usage beyond built-in JavaScript features like `Array.from()`, `Math.random()`, and `JSON.stringify()`/`JSON.parse()`. **Special JS feature or syntax:** There are no special JavaScript features or syntax used in this benchmark. It only relies on standard JavaScript language constructs. **Alternatives:** If you need to compare serialization approaches, here are some alternative test cases you could consider: 1. **Blob-based serialization**: Instead of using `ArrayBuffer`, use the Blob API to serialize and deserialize data. 2. **Typed arrays**: Use other typed array types like Int8Array or Float64Array for serialization. 3. **Big Integers**: Compare serialization performance with Big Integers, which can be more efficient for large numbers. Keep in mind that the choice of alternative test cases depends on your specific use case and requirements.
Related benchmarks:
Lodash cloneDeep vs JSON Cloneeeee
Lodash cloneDeep vs structuredClone vs JSON.stringify with array values
Lodash cloneDeep vs structuredClone vs JSON Parse (deep object)
Lodash cloneDeep vs structuredClone vs JSON-JSON
Lodash cloneDeep vs structuredClone vs JSON.parse + JSON.stringify but with big data
Comments
Confirm delete:
Do you really want to delete benchmark?