Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
msgpack vs json 2
(version: 0)
Comparing performance of:
MessagePack.encode vs JSON.parse
Created:
5 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}]}]}; var strBuf = JSON.stringify(data); var buf = MessagePack.encode(data);
Tests:
MessagePack.encode
var result = MessagePack.decode(buf);
JSON.parse
var result = JSON.parse(strBuf);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
MessagePack.encode
JSON.parse
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
MessagePack.encode
142591.9 Ops/sec
JSON.parse
274072.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and its various components. **Benchmark Overview** The benchmark is designed to compare the performance of two data serialization formats: MessagePack (MP) and JSON (JavaScript Object Notation). The benchmark consists of a single test case, where two different scripts are run to measure their execution time. **Test Case 1: MessagePack.encode** This script prepares a large data structure in MP format using the `MessagePack.encode()` function. The data structure is defined as a nested object with various properties, including integers, strings, and arrays. The prepared data is then converted to a string buffer using `JSON.stringify()`. Finally, the `MessagePack.encode()` function is called to encode the data buffer into MP format. **Test Case 2: JSON.parse** This script prepares a similar large data structure in JSON format using `JSON.stringify()`. The same nested object is defined as in the previous test case. After preparing the data, it is converted to a string buffer and passed directly to the `JSON.parse()` function for decoding. **Options Compared** The two test cases compare the following options: * MessagePack (MP) vs. JSON * Encoding a large data structure using MP vs. encoding using JSON **Pros and Cons of Each Approach** * **MessagePack** + Pros: - Smaller binary size compared to JSON, which can lead to faster transmission and storage. - Can be more efficient for larger data structures due to its compact representation. + Cons: - Less widely supported than JSON, with a smaller community and fewer libraries available. * **JSON** + Pros: - Widely supported by most programming languages and libraries. - Human-readable format makes it easier to debug and understand data structures. + Cons: - Larger binary size compared to MP, which can lead to slower transmission and storage. **Library: MessagePack** The `@msgpack/msgpack` library is used in the benchmark to encode and decode the data structure. This library provides a convenient API for working with MP format, allowing developers to easily serialize and deserialize large data structures. **Special JS Feature: None** There are no special JavaScript features or syntaxes being tested in this benchmark. **Other Alternatives** If MessagePack is not an option, other alternatives for encoding and decoding data structures include: * Protocol Buffers (protobuf): A binary format developed by Google that provides efficient serialization and deserialization. * XML: An extensible markup language that can be used to represent data structures in a human-readable format. Overall, the benchmark provides a simple yet informative comparison of MessagePack and JSON performance for encoding and decoding large data structures.
Related benchmarks:
JSON stringification versus simple map
compare arrays 22
msgpack vs json - encode
msgpack-lite vs json vs pako gzip
Comments
Confirm delete:
Do you really want to delete benchmark?