Skip to content

Commit 796d0c8

Browse files
authored
Merge pull request #5 from fastfloat/add_algorithm
Add algorithms to the benchmark
2 parents 2c6a2fd + 37aebd9 commit 796d0c8

File tree

13 files changed

+432
-112
lines changed

13 files changed

+432
-112
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
build
2+
build_debug
3+
build_script
4+
.cache

CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ set(CMAKE_CXX_STANDARD 17)
55
set(CMAKE_CXX_STANDARD_REQUIRED ON)
66
set(CMAKE_C_STANDARD 99)
77
set(CMAKE_C_STANDARD_REQUIRED ON)
8+
9+
cmake_policy(SET CMP0169 OLD) # Prevent warning when using FetchContent_Populate
10+
811
include(CheckCXXCompilerFlag)
912
unset(FASTPFOR_COMPILER_SUPPORTS_MARCH_NATIVE CACHE)
1013
CHECK_CXX_COMPILER_FLAG(-march=native FASTPFOR_COMPILER_SUPPORTS_MARCH_NATIVE)
@@ -13,11 +16,12 @@ if(FASTPFOR_COMPILER_SUPPORTS_MARCH_NATIVE)
1316
else()
1417
message(STATUS "native target not supported")
1518
endif()
19+
1620
if (NOT CMAKE_BUILD_TYPE)
1721
message(STATUS "No build type selected, default to Release")
1822
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
1923
endif()
2024
include(cmake/CPM.cmake)
21-
add_subdirectory(dependencies)
2225

23-
add_subdirectory(benchmarks)
26+
add_subdirectory(dependencies)
27+
add_subdirectory(benchmarks)

README.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
# float_serialization_benchmark
22

3-
This repository contains benchmarking code for
4-
3+
This repository contains benchmarking code for floating-point serialization.
4+
The goal is to compare different approaches to serializing floating-point
5+
numbers, i.e., converting them from an IEEE 754 binary representation to a
6+
string decimal representation.
7+
8+
Currently, the following approaches are compared:
9+
- [std::to_string](https://en.cppreference.com/w/cpp/string/basic_string/to_string)
10+
- [fmt::format](https://github.com/fmtlib/fmt)
11+
- [netlib](https://github.com/jwiegley/gdtoa)
12+
- [sprintf](https://en.cppreference.com/w/c/io/fprintf)
13+
- [grisu2](https://github.com/simdjson/simdjson/blob/master/src/to_chars.cpp)
14+
- [grisu-exact](https://github.com/jk-jeon/Grisu-Exact)
15+
- [std::to_chars](https://en.cppreference.com/w/cpp/utility/to_chars)
16+
- [Dragonbox](https://github.com/jk-jeon/dragonbox)
17+
- [Ryu](https://github.com/ulfjack/ryu)
18+
- [double-conversion](https://github.com/google/double-conversion)
19+
- [Abseil](https://github.com/abseil/abseil-cpp)
20+
- [Teju Jagua](https://github.com/cassioneri/teju_jagua)
521

622
If you have a recent version of CMake (3.15 or better) under linux, you can simply
723
go in the directory and type the following commands:
@@ -12,11 +28,8 @@ cmake --build build
1228
./build/benchmarks/benchmark
1329
```
1430

15-
16-
1731
You may use docker to run these benchmarks easily on a variety of platforms: see https://github.com/lemire/docker_programming_station
1832

19-
2033
## Windows
2134

2235
Usage under Windows is similar. After installing cmake and Visual Studio 2019, one might type in the appropriate shell:
@@ -37,12 +50,12 @@ Serialize the strings (one per line) included in a text file:
3750

3851
Serialize strings generated from floats in (0,1):
3952

40-
4153
```
4254
./build/benchmarks/benchmark
4355
```
4456

45-
## References
57+
## Other existing benchmarks
4658

4759
- [dtoa Benchmark](https://github.com/miloyip/dtoa-benchmark)
48-
- [Benchmark different approaches to parsing scientific datafiles](https://github.com/alugowski/parse-bench)
60+
- [parse-bench](https://github.com/alugowski/parse-bench)
61+
- [Drackennest](https://github.com/abolz/Drachennest)

benchmarks/CMakeLists.txt

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
1-
add_executable(benchmark benchmark.cpp)
2-
target_link_libraries(benchmark PUBLIC grisu2)
3-
if (NOT CYGWIN)
4-
target_link_libraries(benchmark PUBLIC absl::strings)
5-
endif()
6-
target_link_libraries(benchmark PUBLIC double-conversion)
7-
target_link_libraries(benchmark PUBLIC ryu::ryu)
8-
target_link_libraries(benchmark PUBLIC fmt)
9-
target_link_libraries(benchmark PUBLIC cxxopts)
10-
if(NOT WIN32)
11-
target_link_libraries(benchmark PUBLIC netlib)
12-
target_compile_definitions(benchmark PUBLIC NETLIB_SUPPORTED=1)
13-
endif()
14-
15-
target_link_libraries(benchmark PUBLIC dragonbox::dragonbox_to_chars)
1+
add_executable(benchmark
2+
benchmark.cpp
3+
ieeeToString.cpp
4+
)
165

176
include(CheckSourceCompiles)
18-
197
check_source_compiles(CXX "
208
#include <charconv>
219
int main(void) {
@@ -28,4 +16,28 @@ int main(void) {
2816

2917
if (from_chars_double)
3018
target_compile_definitions(benchmark PUBLIC FROM_CHARS_DOUBLE_SUPPORTED=1)
31-
endif()
19+
endif()
20+
21+
if (NOT WIN32)
22+
target_link_libraries(benchmark PUBLIC netlib)
23+
target_compile_definitions(benchmark PUBLIC NETLIB_SUPPORTED=1)
24+
endif()
25+
26+
if (NOT CYGWIN)
27+
target_link_libraries(benchmark PUBLIC absl::strings)
28+
endif()
29+
30+
target_link_libraries(benchmark PUBLIC fmt)
31+
target_link_libraries(benchmark PUBLIC cxxopts)
32+
33+
target_link_libraries(benchmark PUBLIC grisu2)
34+
target_link_libraries(benchmark PUBLIC double-conversion)
35+
target_link_libraries(benchmark PUBLIC ryu::ryu)
36+
target_link_libraries(benchmark PUBLIC teju)
37+
if(teju_has_float128)
38+
target_link_libraries(benchmark PUBLIC teju_boost_multiprecision)
39+
endif()
40+
target_link_libraries(benchmark PUBLIC dragonbox::dragonbox_to_chars)
41+
target_link_libraries(benchmark PUBLIC dragon_schubfach_lib)
42+
43+
target_include_directories(benchmark PUBLIC ${grisu-exact_SOURCE_DIR})

0 commit comments

Comments
 (0)