Code Monkey home page Code Monkey logo

json_performance's Introduction

json_performance

Performance profiling of JSON libraries

Latest results (May 13, 2024):

Library Roundtrip Time (s) Write (MB/s) Read (MB/s)
Glaze 1.25 1058 1096
simdjson (on demand) N/A N/A 1198
jsonifier 1.55 1019 730
yyjson 1.22 1001 1111
daw_json_link 2.95 362 552
RapidJSON 3.68 287 441
Boost.JSON (direct) 4.77 201 442
json_struct 5.49 182 330
nlohmann 15.12 87 82

1,000,000 iterations on a single core (MacBook Pro M1) - Compiled with Clang 15

Performance caveats: simdjson and yyjson are great, but they experience major performance losses when the data is not in the expected sequence or any keys are missing (the problem grows as the file size increases, as they must re-iterate through the document).

Also, simdjson and yyjson do not support automatic escaped string handling, so if any of the currently non-escaped strings in this benchmark were to contain an escape, the escapes would not be handled.

Note: daw_json_link does not easily support reading with missing keys. So, the code is not tested with this functionality like the rest of the libraries. If missing keys are expected daw_json_link suffers significant performance losses.

Test object (minified for test):

{
   "fixed_object": {
      "int_array": [0, 1, 2, 3, 4, 5, 6],
      "float_array": [0.1, 0.2, 0.3, 0.4, 0.5, 0.6],
      "double_array": [3288398.238, 233e22, 289e-1, 0.928759872, 0.22222848, 0.1, 0.2, 0.3, 0.4]
   },
   "fixed_name_object": {
      "name0": "James",
      "name1": "Abraham",
      "name2": "Susan",
      "name3": "Frank",
      "name4": "Alicia"
   },
   "another_object": {
      "string": "here is some text",
      "another_string": "Hello World",
      "escaped_text": "{\"some key\":\"some string value\"}",
      "boolean": false,
      "nested_object": {
         "v3s": [[0.12345, 0.23456, 0.001345],
                  [0.3894675, 97.39827, 297.92387],
                  [18.18, 87.289, 2988.298]],
         "id": "298728949872"
      }
   },
   "string_array": ["Cat", "Dog", "Elephant", "Tiger"],
   "string": "Hello world",
   "number": 3.14,
   "boolean": true,
   "another_bool": false
}

ABC Test (Out of Sequence Performance)

In this test the JSON document has keys from "a" to "z", where each key refers to an array of integers from [0, 999]. The document orders the keys from "z" to "a", in reverse order to the expected "a" to "z" layout.

This test demonstrates problems with simdjson and iterative parsers that cannot hash for memory locations. If keys are not in the expected sequence performance seriously suffers, and the problem increases as the size of the document increases.

Hash based solutions avoid this problem and do not suffer performance loss as the JSON document grows in size.

Library Read (MB/s)
Glaze 1292
jsonifier 838
simdjson (on demand) 109

json_performance's People

Contributors

beached avatar ibireme avatar jorgen avatar mwalcott3 avatar oipo avatar pdimov avatar realtimechris avatar stephenberry avatar toge avatar waqar144 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

json_performance's Issues

[FYI] glaze has almost reached the performance of simdjson on Ryzen 5600X!

Great work!
I ran latest json_performance on Ryzen 5600X with gcc 12.2.
I found glaze has great improvement!

Now I think there are no reason to choose other libraries on performance side.

Library Roundtrip Time (s) Write (MB/s) Read (MB/s)
Glaze 1.33 810 1120
simdjson (on demand) N/A N/A 1153
yyjson 1.67 743 1036
daw_json_link 2.90 382 492
RapidJSON 2.82 444 557
json_struct 4.52 247 307
nlohmann 14.21 118 83
Library Roundtrip Time (s) Write (MB/s) Read (MB/s)
Glaze 1.69 1241 1067
simdjson (on demand) N/A N/A 111

Performance of simdjson on GCC much slower

Hi,

Maybe I'm doing something wrong, so could be that this is not an issue/more like a question.

I'm trying to run this benchmark with g++ (GCC) 12.1.1. and I get following results (for reading) :

NLOHMANN
nlohmann json byte length: 863
nlohmann json read: 34.2938 s, 2.39991 MB/s

GLAZE
Glaze json byte length: 863
Glaze json read: 1.44985 s, 56.7661 MB/s

SIMDJSON
simdjson (on demand) json byte length: 617
simdjson (on demand) json read: 4.18398 s, 14.0636 MB/s

RAPIDJSON
RapidJSON json byte length: 863
RapidJSON json read: 4.28463 s, 19.2087 MB/s

It seems that simdjson is slower than rapidjson and glaze. Do you have an idea why is this the case? Is it connected to SIMD or? Did you test it on gcc?

Thanks in advance! :)

Interested in yyjson?

I try comparing yyjson with other parsers by using this benchmark code.

I wrote easy code and am in the process of checking the validity of the code, but yyjson seems to run quite fast.
https://github.com/toge/json_performance/tree/add-yyjson

Could you merge it into the benchmark?
If you are going to write your own code, you may reference it.
I will create a PR if necessary.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.