{"id":20887977,"url":"https://github.com/canop/bench-config-deserializers","last_synced_at":"2025-05-12T20:30:46.566Z","repository":{"id":204120096,"uuid":"710874163","full_name":"Canop/bench-config-deserializers","owner":"Canop","description":"A benchmark of Rust/serde deserializers on configuration files","archived":false,"fork":false,"pushed_at":"2023-10-31T16:04:19.000Z","size":31,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-01T10:35:48.137Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Canop.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-10-27T16:10:40.000Z","updated_at":"2023-10-30T15:08:27.000Z","dependencies_parsed_at":"2023-10-31T12:29:54.785Z","dependency_job_id":null,"html_url":"https://github.com/Canop/bench-config-deserializers","commit_stats":null,"previous_names":["canop/bench-config-deserializers"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Canop%2Fbench-config-deserializers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Canop%2Fbench-config-deserializers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Canop%2Fbench-config-deserializers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Canop%2Fbench-config-deserializers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Canop","download_url":"https://codeload.github.com/Canop/bench-config-deserializers/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253816655,"owners_count":21968861,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-18T08:23:40.656Z","updated_at":"2025-05-12T20:30:45.787Z","avatar_url":"https://github.com/Canop.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n## Purpose and methodology\n\nThis program compares the time some [serde](https://serde.rs/) deserializers take to deserialize some string into a configuration-like struct deriving `Deserialize`.\n\nThe benchmarker also checks the correct round-trip by checking equality of the deserialized config with the source struct (this involves enabling the `float_roundtrip` feature for serde_json).\n\nA configuration file needs comments, and needs to be convenient enough to be written by humans.\nFor those reasons, JSON isn't suitable, so this benchmark is really dedicated to [Hjson](https://hjson.github.io/), [JSON5](https://json5.org/), [YAML](https://en.wikipedia.org/wiki/YAML), and [TOML](https://toml.io/). For a deeper discussion regarding the choice of a configuration format, read [this blog post about configuration formats](https://dystroy.org/blog/hjson-in-broot/).\n\nThe struct used in this bench is bigger than usual configuration files but otherwise should be quite alike usual configurations.\nIt is generated 10 times with different random seeds, and stored in memory to avoid disk IO perturbing the measurement.\n\n## JSON\n\nThe [serde-json](https://docs.rs/serde_json/), [deser_hjson](https://docs.rs/deser-hjson/), [sonic-rs](https://docs.rs/sonic-rs/), and [json5](https://docs.rs/json5) deserializers are measured with the same JSON file built by serde_json with `to_string_pretty`.\n\nJSON is a subset of both Hjson and JSON5, that's why a JSON file can be used to benchmark their parsers.\n\nserde_json and sonic_rs are advantaged here, because they don't need to test for meany things you'd normally find in configurations: comments, multi-line texts, alternate ways to write data.\nThey're still interesting as reference points for other deserializers as long as you remember they're not exactly doing the same work.\n\nIn this benchmark, the JSON5 deserializer appears slower than other ones.\nIt's very probable it doesn't matter for you: deserializing a standard configuration is still done in less than 10 ms.\n\n## TOML\n\nThe [toml](https://docs.rs/toml/) and [basic-toml](https://docs.rs/basic-toml/) deserializers are tested with the same struct, but encoded in a TOML string.\n\n## YAML\n\nThe [serde_yaml](https://docs.rs/serde_yaml/) deserializer is tested with the same struct, but encoded in a YAML string.\n\n## Results\n\nHere are the results I get on my computer:\n\n    Fastest deserializer: serde_json\n    ┌───────────┬─────────────┬─────────────────┬──────────┐\n    │   crate   │sum durations│diff with fastest│throughput│\n    ├───────────┼─────────────┼─────────────────┼──────────┤\n    │serde_json │   40.79965ms│              +0%│  506 Mb/s│\n    │ sonic-rs  │  43.144377ms│              +6%│  478 Mb/s│\n    │deser-hjson│  91.190384ms│            +124%│  226 Mb/s│\n    │serde_yaml │ 341.829977ms│            +738%│   46 Mb/s│\n    │basic-toml │ 361.738851ms│            +787%│   39 Mb/s│\n    │   toml    │ 466.519594ms│           +1043%│   31 Mb/s│\n    │   json5   │ 854.551969ms│           +1995%│   24 Mb/s│\n    └───────────┴─────────────┴─────────────────┴──────────┘\n\nA smaller \"diff with fastest\" is better, it's based on the sum of the durations of 10 random strings, with a size varying between 1 and 2 MB.\n\nThe througput is a little less relevant as some formats are more compact. In the specific serialization we do here, the TOML string is smaller than the JSON string (but depending on how you write it yourself, you may get different results).\n\nTo test the benchmark yourself with your hardware, use\n\n    cargo run +nightly --release\n\nThe `+nightly` is required by sonic_rs.\n\nIf you think some common or tricky patterns aren't well tested, that a config deserializer is missing, that I made an error, etc. please create an issue or contact me on [Miaou](https://miaou.dystroy.org/3768).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcanop%2Fbench-config-deserializers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcanop%2Fbench-config-deserializers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcanop%2Fbench-config-deserializers/lists"}