A benchmark of Rust/serde deserializers on configuration files

Overview

This program compares the time some serde deserializers take to deserialize some string into a configuration-like struct deriving Deserialize.

The 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).

A configuration file needs comments, and needs to be convenient enough to be written by humans. For those reasons, JSON isn't suitable, so this benchmark is really dedicated to Hjson, JSON5, YAML, and TOML. For a deeper discussion regarding the choice of a configuration format, read this blog post about configuration formats).

The serde-json, deser_hjson, sonic-rs, and json5 deserializers are measured with the same JSON file built by serde_json with to_string_pretty.

serde_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. They're still interesting as reference points for other deserializers as long as you remember they're not exactly doing the same work.

In this benchmark, the JSON5 deserializer appears slower than other ones. It's very probable it doesn't matter for you: deserializing a standard configuration is still done in less than 10 ms.

The toml deserializer is tested with the same struct, but encoded in a TOML string. The serde_yaml deserializer is tested with the same struct, but encoded in a YAML string.

The struct used in this bench is bigger than usual configuration files but otherwise should be quite alike usual configurations. It is generated 10 times with different random seeds.

Here are the results I get on my computer:

Fastest deserializer: serde_json
┌────────────┬─────────────┬─────────────────┬──────────┐
│deserializer│sum durations│diff with fastest│throughput│
├────────────┼─────────────┼─────────────────┼──────────┤
│ serde_json │  38.061465ms│              +0%│  521 Mb/s│
│  sonic-rs  │  45.537732ms│             +20%│  436 Mb/s│
│deser-hjson │   87.78362ms│            +131%│  226 Mb/s│
│   json5    │ 817.185345ms│           +2047%│   24 Mb/s│
│    toml    │ 436.907208ms│           +1048%│   31 Mb/s│
│ serde_yaml │ 321.301263ms│            +744%│   47 Mb/s│
└────────────┴─────────────┴─────────────────┴──────────┘
(a smaller "diff with fastest" is better)

To test the benchmark yourself with your hardware, use

cargo run +nightly --release

The +nightly is required by sonic_rs.

If 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.

You might also like...
CLI program written in Rust to anonymize DICOM files

dicom-anonymizer CLI program written in Rust to anonymize DICOM files anonymizer 0.1.0 Domenic Melcher USAGE: anonymizer [OPTIONS] FILE ARGS:

A simple path traversal checker made with Rust. Useful for APIs that serve dynamic files.

Path trav A simple path traversal checker made with Rust. Useful for APIs that serve dynamic files. Note: this is a security tool. If you see somethin

Generate rust structs & query functions from diesel schema files

dsync A utility to generate database structs and querying code from diesel schema files. Primarily built for create-rust-app. Currently, it's more adv

Rust library for concurrent data access, using memory-mapped files, zero-copy deserialization, and wait-free synchronization.

mmap-sync mmap-sync is a Rust crate designed to manage high-performance, concurrent data access between a single writer process and multiple reader pr

Create archives of files within Garry's Mod

gm_zip Create archives of files within Garry's Mod. Note: The scope of this module only works accross the gmod installation files e.g from GarrysMod/g

A tool and library to losslessly join multiple .mp4 files shot with same camera and settings

mp4-merge A tool and library to losslessly join multiple .mp4 files shot with same camera and settings. This is useful to merge multiple files that ar

Checks Crusader Kings 3 user mod files for common mistakes and warns about them.

ck3-tiger Pounces on bugs. Checks Crusader Kings 3 user mod files for common mistakes and warns about them. For example: missing localizations, or usi

Send Youtube videos as audio podcasts to your personal Pocket Casts files section.

yttopocketcasts Send Youtube videos as audio podcasts to your personal Pocket Casts files section. Quick Start Prerequisites: Docker and Make must be

A tiny service that downloads files over HTTP links, with resume and restart support.
A tiny service that downloads files over HTTP links, with resume and restart support.

Http Drogue Http Drogue is a tiny service that downloads files over HTTP from links you provide. It can restart and resume interrupted downloads. Http

Owner
Denys Séguret
Freelance Rust programmer
Denys Séguret
Single-side boolean deserializers.

serde-bool Single value, true or false, boolean deserializers. Examples Supporting serde untagged enums where only one boolean value is valid, allowin

null 5 Dec 3, 2023
rusty-riscy is a performance testing and system resource monitoring tool written in Rust to benchmark RISC-V processors.

rusty-riscy rusty-riscy is a performance testing and system resource monitoring tool written in Rust to benchmark RISC-V processors. Objectives To cre

Suhas KV 4 May 3, 2022
A rust-based benchmark for BlueField SmartNICs.

Smartbench Smart-bench is a rust-based benchmarking tool for BlueField-series SmartNICs. The purpose is to enable easy testing of BlueField-series Sma

null 4 Jun 15, 2023
Serialize & deserialize device tree binary using serde

serde_device_tree Use serde framework to deserialize Device Tree Blob binary files; no_std compatible. Use this library Run example: cargo run --examp

Luo Jia 20 Aug 20, 2022
Macro for fast implementing serialize methods in serde::Serializer trait

impl_serialize! This library provides a simple procedural macro for fast implementing serialize methods in serde::Serializer trait. [dependencies] imp

Eduard Baturin 2 Sep 6, 2022
Procedural macro to derive Serde serializer-deserializer for Prost

prost-serde-derive prost-serde-derive is a procedural macro to generate Serde serializers and deserializers for Prost-generated structs. Rationale Cur

Park Joon-Kyu 4 Dec 15, 2022
Serde support for n-dimensional arrays from self-describing formats

serde-ndim Overview This crate provides a way to serialize and deserialize arrays of arbitrary dimensionality from self-described formats such as JSON

Ingvar Stepanyan 5 Apr 3, 2023
The utility is designed to check the availability of peers and automatically update them in the Yggdrasil configuration file, as well as using the admin API - addPeer method.

Yggrasil network peers checker / updater The utility is designed to check the availability of peers and automatically update them in the Yggdrasil con

null 6 Dec 25, 2022
This is a lightweight audio-video player built in Rust using FFmpeg libraries. It demonstrates the usage of FFmpeg with Rust to play back video files.

FFmpeg Rust Video Player This is a lightweight audio-video player built in Rust using FFmpeg libraries. It demonstrates the usage of FFmpeg with Rust

Jenin Sutradhar 3 Apr 10, 2024
Rust command-line tool to encrypt and decrypt files or directories with age

Bottle A Rust command-line tool that can compress and encrypt (and decrypt and extract) files or directories using age, gzip, and tar. Bottle has no c

Sam Schlinkert 1 Aug 1, 2022