This repository contains benchmarking code for floating-point serialization. The goal is to compare different approaches to serializing floating-point numbers, i.e., converting them from an IEEE 754 binary representation to a string decimal representation.
Currently, the following approaches are compared:
- dragon4
- std::to_string
- fmt::format
- netlib
- sprintf
- grisu2
- grisu-exact
- Errol
- std::to_chars
- schubfach
- Dragonbox
- Ryu
- double-conversion
- Abseil
- Teju Jagua
- yy_double
- SwiftDtoa
If you have a recent version of CMake under linux or macOS, you can simply go in the directory and type the following commands:
cmake -B build .
cmake --build build
./build/benchmarks/benchmark
Some functionality might be disabled under some systems. For example, under macOS with libc++, some tests might be omitted because it does not yet fully support C++17.
We also support Visual Studio, please refer to the cmake documentation.
You may use docker to run these benchmarks easily on a variety of platforms: see https://github.com/lemire/docker_programming_station
Usage under Windows is similar. After installing cmake and Visual Studio 2019, one might type in the appropriate shell:
cmake -B build .
cmake --build build --config Release
.\build\benchmarks\Release\benchmark.exe
Serialize the strings (one per line) included in a text file:
./build/benchmarks/benchmark -f data/canada.txt
Serialize strings generated from floats in (0,1):
./build/benchmarks/benchmark
We also include an exhaustive check of all 32-bit floats, to verify that we can produce the shortest string representation (measured by the number of significant digits).
Under Linux, you may run the following check:
cmake -B build .
cmake --build build --config Release
./build/benchmarks/exhaustivefloat32
We also include a thorough check of many 64-bit floats, to verify that we can produce the shortest string representation (measured by the number of significant digits).
Under Linux, you may run the following check:
cmake -B build .
cmake --build build --config Release
./build/benchmarks/thoroughfloat64
By default, we compare algorithms that output shortest-significand representation which can round-trip to the original floating-point value. We can also compare algorithms that output fixed-precision representation of a given precision:
./build/benchmarks/benchmark -f data/canada.txt -F [precision]
Note that this only works when we are comparing speeds, not measuring properties
of the algorithms, i.e., we can't use both -F/--fixed
and -t/--test
at the same time.