Skip to content

Commit fd753df

Browse files
committed
add the yy_double algorithm
[source](ibireme/yyjson#200 (comment))
1 parent 30ab5d6 commit fd753df

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>
@@ -222,6 +224,13 @@ int double_conversion(T d, std::span<char>& buffer) {
222224
return strlen(builder.Finalize());
223225
}
224226

227+
// No yy_float implementation
228+
template<arithmetic_float T>
229+
int yy_double(T d, std::span<char>& buffer) {
230+
const char* end_ptr = yy_double_to_string(d, buffer.data());
231+
return end_ptr - buffer.data();
232+
}
233+
225234
template<arithmetic_float T>
226235
int abseil(T d, std::span<char>& buffer) {
227236
// 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
@@ -198,6 +198,7 @@ int main(int argc, char **argv) {
198198
args[Benchmarks::ABSEIL] = { "abseil" , Benchmarks::abseil<T> , ABSEIL_SUPPORTED };
199199
args[Benchmarks::STD_TO_CHARS] = { "std::to_chars" , Benchmarks::std_to_chars<T> , TO_CHARS_SUPPORTED };
200200
args[Benchmarks::GRISU3] = { "grisu3" , Benchmarks::grisu3<T> , true };
201+
args[Benchmarks::YY_DOUBLE] = { "yy_double" , Benchmarks::yy_double<T> , true };
201202
return args;
202203
};
203204

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
find_library(MATH_LIBRARY m)
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)