Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
msgpack vs json - encode
(version: 0)
Comparing performance of:
JSON.stringify vs MessagePack.encode
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script crossorigin src="https://unpkg.com/@msgpack/msgpack"></script>
Script Preparation code:
var data = {"L":[{"i":1,"m":1024,"l":1048576,"s":1,"c":2,"f":3,"O":[{"i":1,"k":1},{"i":2,"k":1,"p":1.25},{"i":3,"k":1,"p":2.5},{"i":4,"k":1,"p":3.75},{"i":5,"k":1,"p":5}]},{"i":2,"m":1025,"l":1048577,"s":1,"c":2,"f":3,"O":[{"i":1,"k":1},{"i":2,"k":1,"p":1.25},{"i":3,"k":1,"p":2.5},{"i":4,"k":1,"p":3.75},{"i":5,"k":1,"p":5}]},{"i":3,"m":1026,"l":1048578,"s":1,"c":2,"f":3,"O":[{"i":1,"k":1},{"i":2,"k":1,"p":1.25},{"i":3,"k":1,"p":2.5},{"i":4,"k":1,"p":3.75},{"i":5,"k":1,"p":5}]},{"i":4,"m":1027,"l":1048579,"s":1,"c":2,"f":3,"O":[{"i":1,"k":1},{"i":2,"k":1,"p":1.25},{"i":3,"k":1,"p":2.5},{"i":4,"k":1,"p":3.75},{"i":5,"k":1,"p":5}]},{"i":5,"m":1028,"l":1048580,"s":1,"c":2,"f":3,"O":[{"i":1,"k":1},{"i":2,"k":1,"p":1.25},{"i":3,"k":1,"p":2.5},{"i":4,"k":1,"p":3.75},{"i":5,"k":1,"p":5}]},{"i":6,"m":1029,"l":1048581,"s":1,"c":2,"f":3,"O":[{"i":1,"k":1},{"i":2,"k":1,"p":1.25},{"i":3,"k":1,"p":2.5},{"i":4,"k":1,"p":3.75},{"i":5,"k":1,"p":5}]},{"i":7,"m":1030,"l":1048582,"s":1,"c":2,"f":3,"O":[{"i":1,"k":1},{"i":2,"k":1,"p":1.25},{"i":3,"k":1,"p":2.5},{"i":4,"k":1,"p":3.75},{"i":5,"k":1,"p":5}]},{"i":8,"m":1031,"l":1048583,"s":1,"c":2,"f":3,"O":[{"i":1,"k":1},{"i":2,"k":1,"p":1.25},{"i":3,"k":1,"p":2.5},{"i":4,"k":1,"p":3.75},{"i":5,"k":1,"p":5}]},{"i":9,"m":1032,"l":1048584,"s":1,"c":2,"f":3,"O":[{"i":1,"k":1},{"i":2,"k":1,"p":1.25},{"i":3,"k":1,"p":2.5},{"i":4,"k":1,"p":3.75},{"i":5,"k":1,"p":5}]},{"i":10,"m":1033,"l":1048585,"s":1,"c":2,"f":3,"O":[{"i":1,"k":1},{"i":2,"k":1,"p":1.25},{"i":3,"k":1,"p":2.5},{"i":4,"k":1,"p":3.75},{"i":5,"k":1,"p":5}]}]};
Tests:
JSON.stringify
var result = JSON.stringify(data);
MessagePack.encode
var result = MessagePack.encode(data);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
JSON.stringify
MessagePack.encode
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
15 days ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36
Browser/OS:
Chrome 147 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
JSON.stringify
614651.4 Ops/sec
MessagePack.encode
220109.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Taking a deep breath, let's dive into explaining the benchmark and its components. **Benchmark Overview** The provided JSON represents a benchmarking test case created on MeasureThat.net. The goal of this test is to compare the performance of two serialization formats: JSON (JavaScript Object Notation) and MessagePack. **Script Preparation Code** The script preparation code is a JavaScript snippet that defines a large data structure `data` as a nested object with multiple levels, including arrays (`L`) and objects (`O`). This data structure is used to test the encoding performance of both JSON and MessagePack. **Html Preparation Code** The HTML preparation code includes a script tag that loads the MessagePack library from a CDN (Content Delivery Network). This ensures that the MessagePack library is available for use in the benchmarking test. **Individual Test Cases** There are two individual test cases: 1. **JSON.stringify**: This test case uses the built-in `JSON.stringify()` function to serialize the `data` object and measures its execution time. 2. **MessagePack.encode**: This test case uses the MessagePack library to encode the `data` object and measures its execution time. **Options Compared** The two options being compared are: * JSON (JavaScript Object Notation) with the built-in `JSON.stringify()` function * MessagePack with the loaded MessagePack library **Pros and Cons of Each Approach** 1. **JSON (JSON.stringify())** * Pros: + Widely supported and implemented in most JavaScript engines + Easy to implement and understand + Fast and efficient for small to medium-sized data structures * Cons: + May result in larger binary sizes due to added overhead (e.g., encoding/decoding) + Less efficient than MessagePack for large data structures or high-performance requirements 2. **MessagePack (MessagePack.encode)** * Pros: + Designed specifically for efficient serialization and deserialization of large data structures + Smaller binary sizes compared to JSON due to optimized encoding/decoding algorithms + Faster execution times for large data structures or high-performance requirements * Cons: + Requires additional library loading and setup (e.g., the MessagePack library) + May require more complex implementation and understanding **Other Considerations** When choosing between JSON and MessagePack, consider the following factors: * **Data size and complexity**: For small to medium-sized data structures, JSON might be sufficient. However, for large or complex data structures, MessagePack is likely a better choice. * **Performance requirements**: If high-performance serialization/deserialization is critical, MessagePack might be a better option due to its optimized algorithms. * **Implementation complexity**: JSON is generally easier to implement and understand, while MessagePack requires more knowledge of its encoding/decoding mechanics. **Latest Benchmark Results** The provided benchmark results show the execution times for both test cases on an Opera 102 browser, with a total of 160964.640625 executions per second for `JSON.stringify()` and 99441.046875 executions per second for `MessagePack.encode()`. These results suggest that MessagePack is faster than JSON for this specific use case. Please note that benchmarking results can vary depending on the specific hardware, software, and environment used to run the tests.
Related benchmarks:
for-in to hasOwnProperty vs Object.keys, then loop
JSON stringification versus simple map
msgpack vs json 2
msgpack-lite vs json vs pako gzip
Comments
Confirm delete:
Do you really want to delete benchmark?