Skip to content

Commit ec65450

Browse files
author
Daniel Lemire
committed
udpate
1 parent 406e6e6 commit ec65450

4 files changed

Lines changed: 43 additions & 22 deletions

File tree

benchmarks/src/CMakeLists.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,27 @@ target_compile_options(SerializationTwitterBenchmark PRIVATE -freflection -stdli
6060
# Link sanitizers and libraries
6161
target_link_libraries(SerializationTwitterBenchmark PRIVATE nlohmann_json::nlohmann_json simdjson::simdjson )
6262

63+
target_link_libraries(SerializationBenchmark PRIVATE simdjson-serial nlohmann_json::nlohmann_json simdjson::simdjson)
64+
6365
# cpp-reflect may fail to build on LLVM 19 due to this issue
6466
# https://github.com/hanickadot/compile-time-regular-expressions/issues/307
6567
option(SIMDJSON_BENCH_CPP_REFLECT "include cpp reflect in the benchmarks" OFF)
6668
if(SIMDJSON_BENCH_CPP_REFLECT)
6769
message(STATUS "Including reflect-cpp in the benchmarks.")
6870
add_library(benchmark_reflect_serialization_twitter STATIC benchmark_reflect_serialization_twitter.cpp)
6971
target_link_libraries(benchmark_reflect_serialization_twitter PRIVATE reflectcpp)
72+
7073
target_link_libraries(SerializationTwitterBenchmark PRIVATE benchmark_reflect_serialization_twitter)
71-
target_compile_definitions(benchmark_reflect_serialization_twitter PRIVATE SIMDJSON_BENCH_CPP_REFLECT=1)
72-
endif()
74+
target_compile_definitions(SerializationTwitterBenchmark PRIVATE SIMDJSON_BENCH_CPP_REFLECT=1)
7375

7476

75-
target_link_libraries(SerializationBenchmark PRIVATE simdjson-serial nlohmann_json::nlohmann_json simdjson::simdjson)
77+
add_library(benchmark_reflect_serialization STATIC benchmark_reflect_serialization_twitter.cpp)
78+
target_link_libraries(benchmark_reflect_serialization PRIVATE reflectcpp)
79+
80+
target_link_libraries(SerializationBenchmark PRIVATE benchmark_reflect_serialization)
81+
target_compile_definitions(SerializationBenchmark PRIVATE SIMDJSON_BENCH_CPP_REFLECT=1)
82+
endif()
83+
7684

7785

7886
target_compile_definitions(SerializationTwitterBenchmark PRIVATE JSON_FILE="${CMAKE_CURRENT_SOURCE_DIR}/data/twitter.json")
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "benchmark_reflect_serialization.hpp"
2+
#include "benchmark_helper.hpp"
3+
4+
#include <rfl.hpp>
5+
#include <rfl/json.hpp>
6+
7+
void bench_reflect_cpp(std::vector<User>& data) {
8+
std::string output = rfl::json::write(data);
9+
size_t output_volume = output.size();
10+
printf("# output volume: %zu bytes\n", output_volume);
11+
12+
volatile size_t measured_volume = 0;
13+
pretty_print(
14+
1, output_volume, "bench_reflect_cpp",
15+
bench([&data, &measured_volume, &output_volume] () {
16+
std::string output = rfl::json::write(data);
17+
measured_volume = output.size();
18+
if(measured_volume != output_volume) { printf("mismatch\n"); }
19+
})
20+
);
21+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef BENCHMARK_REFLECT_SERIALIZATION_TWITTER_HPP
2+
#define BENCHMARK_REFLECT_SERIALIZATION_TWITTER_HPP
3+
4+
#include "user_profile.hpp"
5+
void bench_reflect_cpp(std::vector<User>& data)
6+
#endif

benchmarks/src/benchmark_serialization.cpp

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
#include <vector>
1111
#include <format>
1212
#include <atomic>
13-
#include <rfl.hpp>
14-
#include <rfl/json.hpp>
1513
#include "user_profile.hpp"
1614
#include "custom_serializer.h"
1715
#include "nlohmann_user_profile.hpp"
18-
16+
#if SIMDJSON_BENCH_CPP_REFLECT
17+
#include "benchmark_reflect_serialization.hpp"
18+
#endif
1919
std::string generate_email(const std::string &name,
2020
const std::string &company) {
2121
std::string email = name + "@" + company + ".com";
@@ -231,21 +231,6 @@ void bench_nlohmann(std::vector<User> &data) {
231231
);
232232
}
233233

234-
void bench_reflect_cpp(std::vector<User>& data) {
235-
std::string output = rfl::json::write(data);
236-
size_t output_volume = output.size();
237-
printf("# output volume: %zu bytes\n", output_volume);
238-
239-
volatile size_t measured_volume = 0;
240-
pretty_print(
241-
1, output_volume, "bench_reflect_cpp",
242-
bench([&data, &measured_volume, &output_volume] () {
243-
std::string output = rfl::json::write(data);
244-
measured_volume = output.size();
245-
if(measured_volume != output_volume) { printf("mismatch\n"); }
246-
})
247-
);
248-
}
249234

250235

251236
int main() {
@@ -257,7 +242,8 @@ int main() {
257242
bench_nlohmann(test_data);
258243
bench_custom(test_data);
259244
bench_fast_simpler(test_data);
245+
#if SIMDJSON_BENCH_CPP_REFLECT
260246
bench_reflect_cpp(test_data);
261-
247+
#endif
262248
return EXIT_SUCCESS;
263249
}

0 commit comments

Comments
 (0)