Skip to content

Commit ec7c3ee

Browse files
committed
add grisu-exact algorithm in the benchmarks
1 parent 0d7b41c commit ec7c3ee

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Currently, the following approaches are compared:
1111
- [netlib](https://github.com/jwiegley/gdtoa)
1212
- [sprintf](https://en.cppreference.com/w/c/io/fprintf)
1313
- [grisu2](https://github.com/simdjson/simdjson/blob/master/src/to_chars.cpp)
14+
- [grisu-exact](https://github.com/jk-jeon/Grisu-Exact)
1415
- [std::to_chars](https://en.cppreference.com/w/cpp/utility/to_chars)
1516
- [Dragonbox](https://github.com/jk-jeon/dragonbox)
1617
- [Ryu](https://github.com/ulfjack/ryu)

benchmarks/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ target_link_libraries(benchmark PUBLIC double-conversion)
3535
target_link_libraries(benchmark PUBLIC ryu::ryu)
3636
target_link_libraries(benchmark PUBLIC teju)
3737
target_link_libraries(benchmark PUBLIC dragonbox::dragonbox_to_chars)
38+
39+
target_include_directories(benchmark PUBLIC ${grisu-exact_SOURCE_DIR})

benchmarks/benchmark.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "dragonbox/dragonbox_to_chars.h"
1818
#include "ryu/ryu.h"
1919
#include "double-conversion/double-conversion.h"
20+
#include "grisu_exact.h"
2021

2122
#define IEEE_8087
2223
#include "benchutil.h"
@@ -58,6 +59,7 @@ void process(std::vector<double> &lines) {
5859
}
5960
return volume;
6061
});
62+
6163
pretty_print(lines, "fmt::format", [](const std::vector<double> &lines) {
6264
double volume = 0;
6365
for (const auto d : lines) {
@@ -66,6 +68,7 @@ void process(std::vector<double> &lines) {
6668
}
6769
return volume;
6870
});
71+
6972
#if NETLIB_SUPPORTED
7073
pretty_print(lines, "netlib", [](const std::vector<double> &lines) {
7174
double volume = 0;
@@ -87,6 +90,7 @@ void process(std::vector<double> &lines) {
8790
#else
8891
std::cout << "# netlib not supported" << std::endl;
8992
#endif
93+
9094
pretty_print(lines, "sprintf", [](const std::vector<double> &lines) {
9195
double volume = 0;
9296
char buffer[100];
@@ -95,6 +99,7 @@ void process(std::vector<double> &lines) {
9599
}
96100
return volume;
97101
});
102+
98103
pretty_print(lines, "grisu2", [](const std::vector<double> &lines) {
99104
double volume = 0;
100105
char buffer[100];
@@ -104,6 +109,17 @@ void process(std::vector<double> &lines) {
104109
}
105110
return volume;
106111
});
112+
113+
pretty_print(lines, "grisu_exact", [](const std::vector<double> &lines) {
114+
double volume = 0;
115+
char buffer[100];
116+
for (const auto d : lines) {
117+
auto v = jkj::grisu_exact(d);
118+
volume += to_chars(v.significand, v.exponent, v.is_negative, buffer);
119+
}
120+
return volume;
121+
});
122+
107123
#if FROM_CHARS_DOUBLE_SUPPORTED
108124
pretty_print(lines, "std::to_chars", [](const std::vector<double> &lines) {
109125
double volume = 0;
@@ -121,6 +137,7 @@ void process(std::vector<double> &lines) {
121137
#else
122138
std::cout << "# std::to_chars not supported" << std::endl;
123139
#endif
140+
124141
pretty_print(lines, "dragonbox", [](const std::vector<double> &lines) {
125142
double volume = 0;
126143
char buffer[100];

dependencies/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ FetchContent_Declare(
5050
)
5151
FetchContent_MakeAvailable(ryu)
5252

53+
FetchContent_Declare(
54+
grisu-exact
55+
GIT_REPOSITORY https://github.com/jk-jeon/Grisu-Exact
56+
GIT_TAG master
57+
GIT_SHALLOW TRUE
58+
)
59+
FetchContent_MakeAvailable(grisu-exact)
60+
set(grisu-exact_SOURCE_DIR ${grisu-exact_SOURCE_DIR} PARENT_SCOPE)
61+
5362
FetchContent_Declare(
5463
dragonbox
5564
GIT_REPOSITORY https://github.com/jk-jeon/dragonbox

0 commit comments

Comments
 (0)