Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Benchmark: BSON vs JSON

Following this benchmark BSON needs more disk-space, time to create, serialize, deserialize and traverse all elements. The big advantage of BSON is, that it's much faster in traversing. So what's wrong with this benchmark?

like image 343
rednammoc Avatar asked Aug 23 '11 20:08

rednammoc


People also ask

Is BSON better than JSON?

BSON is also designed in a way that it has a comparatively faster encoding and decoding technique. For example, all those integers stored as 32-bit integers so that they are not parsed with them to and from the text. Therefore, it uses more space than JSON for smaller integers, but BSON is anyway much faster to parse.

Why is BSON faster?

BSON's binary structure encodes type and length information, which allows it to be parsed much more quickly.

Is BSON smaller than JSON?

For an integer field, the JSON length depends on the size of the number. "1" is just one byte. "1000000" is 7 bytes. In BSON both of these would be a 4 byte 32 bit integer.

Why does MongoDB use BSON rather than JSON?

BSON needs to be parsed as they are machine-generated and not human-readable. JSON has a specific set of data types—string, boolean, number for numeric data types, array, object, and null. Unlike JSON, BSON offers additional data types such as bindata for binary data, decimal128 for numeric.


1 Answers

Your question is unclear. Who claims that "The big advantage of BSON is, that it's much faster in traversing."? Wikipedia says that BSON is designed "to be efficient both in storage space and scan-speed" - but that only means that designers tried, not that they succeeded.

Note that the benchmark compares many JSON implementation, and there are both faster and slower ones; apparently somebody spent a lot of time writing optimized JSON parsers - indeed FastJson website explains (in Chinese, which I read through Google Translate) a number of advanced implementation techniques.

See also Performant Entity Serialization: BSON vs MessagePack (vs JSON)

Bottom line: the benchmark might be wrong or might also have nothing wrong. The authors suggest to try reproduce the data for your specific scenario, as is good practice in general, since benchmarks are just data points. So try running the benchmark for BSON and FastJSON (or what else has interesting performance for JSON) with data which is representative for you.

like image 125
Blaisorblade Avatar answered Nov 15 '22 15:11

Blaisorblade