Skip to content

Commit 8c13d6b

Browse files
committed
add the yy_double algorithm
[source](ibireme/yyjson#200 (comment))
1 parent d42289d commit 8c13d6b

File tree

6 files changed

+4698
-1
lines changed

6 files changed

+4698
-1
lines changed

benchmarks/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ target_link_libraries(benchmark PUBLIC fmt)
6868
target_link_libraries(benchmark PUBLIC cxxopts)
6969

7070
#target_link_libraries(benchmark PUBLIC grisu2)
71+
target_link_libraries(benchmark PUBLIC yy_double)
7172
target_link_libraries(benchmark PUBLIC double-conversion)
7273
target_link_libraries(benchmark PUBLIC ryu::ryu)
7374
target_link_libraries(benchmark PUBLIC teju)

benchmarks/algorithms.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "ryu/ryu.h"
3333
#include "schubfach_32.h"
3434
#include "schubfach_64.h"
35+
#include "yy_double.h"
3536

3637
namespace Benchmarks {
3738

@@ -52,7 +53,8 @@ enum Algorithm {
5253
ABSEIL = 13,
5354
STD_TO_CHARS = 14,
5455
GRISU3 = 15,
55-
COUNT = 16,
56+
YY_DOUBLE = 16,
57+
COUNT = 17,
5658
};
5759

5860
template<typename T>
@@ -225,6 +227,13 @@ int double_conversion(T d, std::span<char>& buffer) {
225227
return strlen(builder.Finalize());
226228
}
227229

230+
// No yy_float implementation
231+
template<arithmetic_float T>
232+
int yy_double(T d, std::span<char>& buffer) {
233+
const char* end_ptr = yy_double_to_string(d, buffer.data());
234+
return end_ptr - buffer.data();
235+
}
236+
228237
template<arithmetic_float T>
229238
int abseil(T d, std::span<char>& buffer) {
230239
// StrAppend is faster but only outputs 6 digits after the decimal point

benchmarks/benchmark.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ int main(int argc, char **argv) {
205205
args[Benchmarks::ABSEIL] = { "abseil" , Benchmarks::abseil<T> , ABSEIL_SUPPORTED };
206206
args[Benchmarks::STD_TO_CHARS] = { "std::to_chars" , Benchmarks::std_to_chars<T> , TO_CHARS_SUPPORTED };
207207
args[Benchmarks::GRISU3] = { "grisu3" , Benchmarks::grisu3<T> , true };
208+
args[Benchmarks::YY_DOUBLE] = { "yy_double" , Benchmarks::yy_double<T> , true };
208209
return args;
209210
};
210211

dependencies/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
if(NOT WIN32)
22
add_subdirectory(netlib)
33
endif()
4+
add_subdirectory(yy_double)
45
#add_subdirectory(grisu2)
56

67
include(FetchContent)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Source: https://github.com/ibireme/yyjson/issues/200#issuecomment-2726783097
2+
set(HEADER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/yy_double.h)
3+
add_library(yy_double INTERFACE)
4+
target_include_directories(yy_double INTERFACE
5+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
6+
$<INSTALL_INTERFACE:include>
7+
)

0 commit comments

Comments
 (0)