Skip to content

Commit eba7364

Browse files
author
Daniel Lemire
committed
tweak
1 parent 1f90740 commit eba7364

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

benchmarks/src/benchmark_serialization.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,24 @@ template <class T> void bench_fast_with_alloc(std::vector<T> &data) {
198198
}));
199199
}
200200

201+
202+
template <class T> void bench_fast_with_assign(std::vector<T> &data) {
203+
std::string json;
204+
simdjson::json_builder::to_json(data, json);
205+
size_t output_volume = json.size();
206+
printf("# output volume: %zu bytes\n", output_volume);
207+
208+
volatile size_t measured_volume = 0;
209+
pretty_print(data.size(), output_volume, "bench_fast_with_assign",
210+
bench([&data, &measured_volume, &output_volume, &json]() {
211+
simdjson::json_builder::to_json(data, json);
212+
measured_volume = json.size();
213+
if (measured_volume != output_volume) {
214+
printf("mismatch\n");
215+
}
216+
}));
217+
}
218+
201219
void bench_nlohmann(std::vector<User> &data) {
202220
std::string output = nlohmann_serialize(data);
203221
size_t output_volume = output.size();
@@ -225,6 +243,7 @@ int main() {
225243
//bench_custom(test_data);
226244
bench_fast_simpler(test_data);
227245
bench_fast_with_alloc(test_data);
246+
bench_fast_with_assign(test_data);
228247
#if SIMDJSON_BENCH_CPP_REFLECT
229248
bench_reflect_cpp(test_data);
230249
#endif

benchmarks/src/benchmark_serialization_twitter.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,24 @@ template <class T> void bench_fast_with_alloc(T &data) {
5555
}));
5656
}
5757

58+
59+
template <class T> void bench_fast_with_assign(T &data) {
60+
std::string json;
61+
simdjson::json_builder::to_json(data, json);
62+
size_t output_volume = json.size();
63+
printf("# output volume: %zu bytes\n", output_volume);
64+
65+
volatile size_t measured_volume = 0;
66+
pretty_print(sizeof(data), output_volume, "bench_fast_with_assign",
67+
bench([&data, &measured_volume, &output_volume, &json]() {
68+
simdjson::json_builder::to_json(data, json);
69+
measured_volume = json.size();
70+
if (measured_volume != output_volume) {
71+
printf("mismatch\n");
72+
}
73+
}));
74+
}
75+
5876
void bench_nlohmann(TwitterData &data) {
5977
std::string output = nlohmann_serialize(data);
6078
size_t output_volume = output.size();
@@ -190,9 +208,10 @@ int main() {
190208
auto json_value = parser.parse();
191209
TwitterData my_struct;
192210
bench_nlohmann(my_struct);
193-
//simpleparser::json_builder::from_json(json_value, my_struct);
211+
simpleparser::json_builder::from_json(json_value, my_struct);
194212
bench_fast_simpler(my_struct);
195213
bench_fast_with_alloc(my_struct);
214+
bench_fast_with_assign(my_struct);
196215
#if SIMDJSON_BENCH_CPP_REFLECT
197216
bench_reflect_cpp(my_struct);
198217
#endif

0 commit comments

Comments
 (0)