There are a whole bunch of JSON v XML posts out there. So, I will not rehash the various arguments on which is better. However, we needed to select a file format to store configuration information. To make things convenient, we decided to use the Boost::Property_Tree library.

So, this is essentially about how the Boost library performs when parsing JSON and XML. The sample JSON and XML files were obtained from the JSON examples website.

After writing a simple program to perform 10,000 reads and 100 writes, we timed the operation. The programme was compiled with GCC and LLVM with optimisation turned on. The reason we used the 10,000:100 ratio for read and write is because this application will be performing more reads than writes.

The results are:

JSON (GCC): 1.85s
XML  (GCC): 3.07s
JSON(LLVM): 1.69s
XML (LLVM): 2.83s

Seems that the Boost library has a better JSON parser than an XML parser. What is also interesting is that the LLVM compiled code runs about 10% faster than the GCC version.


angch · 2015-06-03 at 17:47

In other news, it seems that C has a better gzip compressor than a bzip2 compressor.

Burak Emir · 2015-07-12 at 02:28

protobuf? : )

    Shawn Tan · 2015-07-12 at 11:48

    I’ll use it if it makes it into Boost or C++17. (:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.