libjson performance benchmark

Anonymous
2011-10-13
2013-06-12

  • Anonymous
    2011-10-13

    Hi,

    I am evaluating the performance of popular c++ json libraries(libjson, jsoncpp, cajun, json_spirit etc) for a project.

    I was wondering whether any one has done this before or has some idea about the performance figures?
    Could you refer me to some documents or blog posts etc?

    Thanks in advance,
    lijo

     
  • Other than my own benchmarks, I've not seen anyone do any.  I'd love to see your results, but libjson has two different parsing engines, which are each optimized for different tasks, so try to use the right one ;)

     

  • Anonymous
    2011-11-19

    Hi,

    I did a comparison and performance benchmarking of popular c++ json libraries.
    libjson performed really well, even without any performance customizations :-). Thanks for the support.
    Please find my analysis here and the source code for the test program here. Share your thoughts!

    Thanks,
    lijo

     
  • Nice to see a good comparison of JSON libraries.  However, I felt that because of libjson's default options, it wasn't entirely fair.  By default, libjson parses nodes lazily.  So libjson::parse parsed far enough to know that it's as a valid object, but then stopped because it doesn't actually parse until it needs to be.  This also speeds up writing because if the internals of a node haven't been parsed yet, it simply echos it out.

    The JSON_PREPARSE option changes libjson's behavior from lazy parsing to all at once parsing.

    I ran your test with the option on and got these results:
    #library                 parsing                  writing                 
    cajun                    1788                     188                     
    libjson                  174                      262

    This is a more realistic comparison because the entirety of the json got parsed and had to be written out.  I took spirit out of the tests because I didn't feel like getting boost.

     

  • Anonymous
    2011-11-23

    That solves the mystery!
    I was puzzled by the libjson performance at first.
    But the consistent read and write numbers made me to believe otherwise.
    Now the numbers make sense. Thanks for the information.

    -lijo

     
  • Still looks like it's about 10 times faster than cajun, not as good as 100 times, but nice.

    Also, thank you for doing this test.  I pride myself on my optimization ability, now that I know that libjson's reading engine is so far ahead of the others, now I know I need to start working on the writing engine.

     
  • Note that the above performance tests that I posted were libjson 7.4.1.  It was unacceptable that libjson writes json slower than cajun, so in libjson 7.5.0, the writing engine was made five times faster.