<script src="https://rawgit.com/kawanet/msgpack-lite/master/dist/msgpack.min.js"></script>
var stringData = {"glossary":{"title":"example glossary","GlossDiv":{"title":"S","GlossList":{"GlossEntry":{"ID":"SGML","SortAs":"SGML","GlossTerm":"Standard Generalized Markup Language","Acronym":"SGML","Abbrev":"ISO 8879:1986","GlossDef":{"para":"A meta-markup language, used to create markup languages such as DocBook.","GlossSeeAlso":["GML","XML"]},"GlossSee":"markup"}}}}};
var numberData = [
[1, 2, 3, 4, -1, true, null],
[3, 6, 5, 4, 1, false, 7],
[3, 2, 8, 1, 0, true, 0],
[10, 11, 12, 13, 14, false, true],
[15, 16, 17, 18, 19, true, null],
[20, 21, 22, 23, 24, false, 7],
[25, 26, 27, 28, 29, true, 0],
100, 200, 300,
[
[1, 0, 0, 0, 0],
[0, 1, 0, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 1, 0],
[0, 0, 0, 0, 1]
]
];
var jsonEncodedStrings = JSON.stringify(stringData),
jsonEncodedNumbers = JSON.stringify(numberData),
msgpackEncodedStrings = msgpack.encode(stringData),
msgpackEncodedNumbers = msgpack.encode(numberData);
var result = msgpack.encode(stringData);
var result = JSON.stringify(stringData);
var result = msgpack.encode(numberData);
var result = JSON.stringify(numberData);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
MsgPack Strings Encode | |
JSON Strings Encode | |
MsgPack Numbers Encode | |
JSON Numbers Encode |
Test name | Executions per second |
---|---|
MsgPack Strings Encode | 273978.7 Ops/sec |
JSON Strings Encode | 3898500.0 Ops/sec |
MsgPack Numbers Encode | 512698.4 Ops/sec |
JSON Numbers Encode | 1964817.0 Ops/sec |
Let's dive into the world of microbenchmarks and explore what's being tested on this benchmark.
Benchmark Overview
The benchmark is designed to compare the performance of two data serialization formats: JSON (JavaScript Object Notation) and MsgPack (a binary-based format). The test cases focus on encoding strings and numbers, which are common use cases in web development.
Options Compared
There are four test cases:
JSON.stringify()
to encode a string.JSON.stringify()
to encode an array of numbers.msgpack.encode()
to encode a string.msgpack.encode()
to encode an array of numbers.Pros and Cons
Other Considerations
msgpack-lite
library is used to implement MsgPack. This library provides a lightweight implementation of the MsgPack format.JSON.stringify()
and msgpack.encode()
functions.Benchmark Results
The latest benchmark results show that:
Alternatives
If you're interested in exploring alternative data serialization formats, consider:
Keep in mind that the choice of data serialization format ultimately depends on your specific use case, performance requirements, and trade-offs between size, speed, and complexity.