Skip to content

Commit d6cf29b

Browse files
Adding reflect-cpp benchmark
1 parent 01c12a1 commit d6cf29b

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ include(cmake/CPM.cmake)
2020
CPMAddPackage("gh:simdjson/simdjson@3.9.4")
2121
CPMAddPackage("gh:nlohmann/json@3.10.5")
2222

23+
# Include reflect-cpp
24+
CPMAddPackage(
25+
NAME reflect-cpp
26+
GITHUB_REPOSITORY getml/reflect-cpp
27+
GIT_TAG main
28+
)
29+
2330
# Optionally, specify the C++ compiler directly (here we use clang++)
2431
add_subdirectory(src)
2532
add_subdirectory(examples)

benchmarks/src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ target_compile_options(SerializationTwitterBenchmark PRIVATE -freflection -stdli
5959
#find_package(CURL REQUIRED)
6060

6161
# Link sanitizers and libraries
62-
target_link_libraries(SerializationTwitterBenchmark PRIVATE nlohmann_json::nlohmann_json simdjson::simdjson)
62+
target_link_libraries(SerializationTwitterBenchmark PRIVATE nlohmann_json::nlohmann_json simdjson::simdjson reflectcpp)
6363
target_link_libraries(SerializationBenchmark PRIVATE simdjson-serial nlohmann_json::nlohmann_json simdjson::simdjson)
6464

6565
target_compile_definitions(SerializationTwitterBenchmark PRIVATE JSON_FILE="${CMAKE_CURRENT_SOURCE_DIR}/data/twitter.json")

benchmarks/src/benchmark_serialization_twitter.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <simdjson.h>
1313
#include <fstream>
1414
#include <nlohmann/json.hpp>
15+
#include <rfl.hpp>
16+
#include <rfl/json.hpp>
1517

1618
event_collector collector;
1719

@@ -90,6 +92,22 @@ void bench_nlohmann(TwitterData &data) {
9092
);
9193
}
9294

95+
void bench_reflect_cpp(TwitterData& data) {
96+
std::string output = rfl::json::write(data);
97+
size_t output_volume = output.size();
98+
printf("# output volume: %zu bytes\n", output_volume);
99+
100+
volatile size_t measured_volume = 0;
101+
pretty_print(
102+
1, output_volume, "bench_reflect_cpp",
103+
bench([&data, &measured_volume, &output_volume] () {
104+
std::string output = rfl::json::write(data);
105+
measured_volume = output.size();
106+
if(measured_volume != output_volume) { printf("mismatch\n"); }
107+
})
108+
);
109+
}
110+
93111
size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userp) {
94112
((std::string*)userp)->append((char*)contents, size * nmemb);
95113
return size * nmemb;
@@ -215,6 +233,7 @@ int main()
215233
experimental_json_builder::from_json(json_value, my_struct);
216234
bench_fast_simpler(my_struct);
217235
bench_nlohmann(my_struct);
236+
bench_reflect_cpp(my_struct);
218237

219238
return EXIT_SUCCESS;
220239
}

0 commit comments

Comments
 (0)