From dcd2e13aecaffdc7dcd514be75daf074539528c0 Mon Sep 17 00:00:00 2001 From: John Keiser Date: Tue, 5 Jan 2021 10:45:49 -0800 Subject: [PATCH] Measure time more accurately --- benchmark/distinct_user_id/rapidjson.h | 4 ++-- benchmark/distinct_user_id/simdjson_dom.h | 2 +- benchmark/distinct_user_id/simdjson_ondemand.h | 2 +- benchmark/distinct_user_id/yyjson.h | 2 +- benchmark/find_tweet/rapidjson.h | 4 ++-- benchmark/find_tweet/simdjson_dom.h | 2 +- benchmark/find_tweet/simdjson_ondemand.h | 2 +- benchmark/find_tweet/yyjson.h | 2 +- benchmark/json_benchmark/run_json_benchmark.h | 4 +++- benchmark/kostya/rapidjson.h | 6 +++--- benchmark/kostya/simdjson_dom.h | 2 +- benchmark/kostya/simdjson_ondemand.h | 2 +- benchmark/kostya/yyjson.h | 2 +- benchmark/large_random/rapidjson.h | 6 +++--- benchmark/large_random/simdjson_dom.h | 2 +- benchmark/large_random/simdjson_ondemand.h | 2 +- benchmark/large_random/simdjson_ondemand_unordered.h | 2 +- benchmark/large_random/yyjson.h | 2 +- benchmark/partial_tweets/rapidjson.h | 9 ++++----- benchmark/partial_tweets/simdjson_dom.h | 2 +- benchmark/partial_tweets/simdjson_ondemand.h | 2 +- benchmark/partial_tweets/yyjson.h | 2 +- 22 files changed, 33 insertions(+), 32 deletions(-) diff --git a/benchmark/distinct_user_id/rapidjson.h b/benchmark/distinct_user_id/rapidjson.h index 25f47deae..88ca310a7 100644 --- a/benchmark/distinct_user_id/rapidjson.h +++ b/benchmark/distinct_user_id/rapidjson.h @@ -43,7 +43,7 @@ struct rapidjson : public rapidjson_base { return rapidjson_base::run(doc.Parse(json.data()), ids); } }; -BENCHMARK_TEMPLATE(distinct_user_id, rapidjson); +BENCHMARK_TEMPLATE(distinct_user_id, rapidjson)->UseManualTime(); struct rapidjson_insitu : public rapidjson_base { bool run(const padded_string &json, std::vector &ids) { @@ -51,7 +51,7 @@ struct rapidjson_insitu : public rapidjson_base { return rapidjson_base::run(doc.ParseInsitu(json_copy.data()), ids); } }; -BENCHMARK_TEMPLATE(distinct_user_id, rapidjson_insitu); +BENCHMARK_TEMPLATE(distinct_user_id, rapidjson_insitu)->UseManualTime(); } // namespace partial_tweets diff --git a/benchmark/distinct_user_id/simdjson_dom.h b/benchmark/distinct_user_id/simdjson_dom.h index 636374c89..2b30ddff9 100644 --- a/benchmark/distinct_user_id/simdjson_dom.h +++ b/benchmark/distinct_user_id/simdjson_dom.h @@ -29,7 +29,7 @@ struct simdjson_dom { } }; -BENCHMARK_TEMPLATE(distinct_user_id, simdjson_dom); +BENCHMARK_TEMPLATE(distinct_user_id, simdjson_dom)->UseManualTime(); } // namespace distinct_user_id diff --git a/benchmark/distinct_user_id/simdjson_ondemand.h b/benchmark/distinct_user_id/simdjson_ondemand.h index d20343132..1d66fbb50 100644 --- a/benchmark/distinct_user_id/simdjson_ondemand.h +++ b/benchmark/distinct_user_id/simdjson_ondemand.h @@ -31,7 +31,7 @@ struct simdjson_ondemand { } }; -BENCHMARK_TEMPLATE(distinct_user_id, simdjson_ondemand); +BENCHMARK_TEMPLATE(distinct_user_id, simdjson_ondemand)->UseManualTime(); } // namespace distinct_user_id diff --git a/benchmark/distinct_user_id/yyjson.h b/benchmark/distinct_user_id/yyjson.h index c4df2722d..80d4601b8 100644 --- a/benchmark/distinct_user_id/yyjson.h +++ b/benchmark/distinct_user_id/yyjson.h @@ -43,7 +43,7 @@ struct yyjson { }; -BENCHMARK_TEMPLATE(distinct_user_id, yyjson); +BENCHMARK_TEMPLATE(distinct_user_id, yyjson)->UseManualTime(); } // namespace distinct_user_id diff --git a/benchmark/find_tweet/rapidjson.h b/benchmark/find_tweet/rapidjson.h index f6d73ab8d..8b88ac6f2 100644 --- a/benchmark/find_tweet/rapidjson.h +++ b/benchmark/find_tweet/rapidjson.h @@ -36,7 +36,7 @@ struct rapidjson : public rapidjson_base { return rapidjson_base::run(doc.Parse(json.data()), find_id, text); } }; -BENCHMARK_TEMPLATE(find_tweet, rapidjson); +BENCHMARK_TEMPLATE(find_tweet, rapidjson)->UseManualTime(); struct rapidjson_insitu : public rapidjson_base { bool run(const padded_string &json, uint64_t find_id, std::string_view &text) { @@ -44,7 +44,7 @@ struct rapidjson_insitu : public rapidjson_base { return rapidjson_base::run(doc.ParseInsitu(json_copy.data()), find_id, text); } }; -BENCHMARK_TEMPLATE(find_tweet, rapidjson_insitu); +BENCHMARK_TEMPLATE(find_tweet, rapidjson_insitu)->UseManualTime(); } // namespace partial_tweets diff --git a/benchmark/find_tweet/simdjson_dom.h b/benchmark/find_tweet/simdjson_dom.h index 57043457a..e1539adc7 100644 --- a/benchmark/find_tweet/simdjson_dom.h +++ b/benchmark/find_tweet/simdjson_dom.h @@ -24,7 +24,7 @@ struct simdjson_dom { } }; -BENCHMARK_TEMPLATE(find_tweet, simdjson_dom); +BENCHMARK_TEMPLATE(find_tweet, simdjson_dom)->UseManualTime(); } // namespace find_tweet diff --git a/benchmark/find_tweet/simdjson_ondemand.h b/benchmark/find_tweet/simdjson_ondemand.h index ea55a3123..e453a7dcb 100644 --- a/benchmark/find_tweet/simdjson_ondemand.h +++ b/benchmark/find_tweet/simdjson_ondemand.h @@ -25,7 +25,7 @@ struct simdjson_ondemand { } }; -BENCHMARK_TEMPLATE(find_tweet, simdjson_ondemand); +BENCHMARK_TEMPLATE(find_tweet, simdjson_ondemand)->UseManualTime(); } // namespace find_tweet diff --git a/benchmark/find_tweet/yyjson.h b/benchmark/find_tweet/yyjson.h index 74052478d..cba30e97e 100644 --- a/benchmark/find_tweet/yyjson.h +++ b/benchmark/find_tweet/yyjson.h @@ -33,7 +33,7 @@ struct yyjson { } }; -BENCHMARK_TEMPLATE(find_tweet, yyjson); +BENCHMARK_TEMPLATE(find_tweet, yyjson)->UseManualTime(); } // namespace find_tweet diff --git a/benchmark/json_benchmark/run_json_benchmark.h b/benchmark/json_benchmark/run_json_benchmark.h index 200b2375e..ed6b373e0 100644 --- a/benchmark/json_benchmark/run_json_benchmark.h +++ b/benchmark/json_benchmark/run_json_benchmark.h @@ -37,7 +37,9 @@ template static void run_json_benchmark(benchmark::State if (!bench.before_run(state)) { state.SkipWithError("before_run failed"); }; collector.start(); if (!bench.run(state)) { state.SkipWithError("run failed"); return; } - events << collector.end(); + auto event = collector.end(); + events << event; + state.SetIterationTime(event.elapsed_sec()); if (!bench.after_run(state)) { state.SkipWithError("after_run failed"); return; }; } diff --git a/benchmark/kostya/rapidjson.h b/benchmark/kostya/rapidjson.h index 57ab314f4..084187118 100644 --- a/benchmark/kostya/rapidjson.h +++ b/benchmark/kostya/rapidjson.h @@ -38,14 +38,14 @@ struct rapidjson : public rapidjson_base { return rapidjson_base::run(doc.Parse(json.data()), points); } }; -BENCHMARK_TEMPLATE(kostya, rapidjson); +BENCHMARK_TEMPLATE(kostya, rapidjson)->UseManualTime(); struct rapidjson_lossless : public rapidjson_base { bool run(const padded_string &json, std::vector &points) { return rapidjson_base::run(doc.Parse(json.data()), points); } }; -BENCHMARK_TEMPLATE(kostya, rapidjson_lossless); +BENCHMARK_TEMPLATE(kostya, rapidjson_lossless)->UseManualTime(); struct rapidjson_insitu : public rapidjson_base { bool run(const padded_string &json, std::vector &points) { @@ -53,7 +53,7 @@ struct rapidjson_insitu : public rapidjson_base { return rapidjson_base::run(doc.ParseInsitu(json_copy.data()), points); } }; -BENCHMARK_TEMPLATE(kostya, rapidjson_insitu); +BENCHMARK_TEMPLATE(kostya, rapidjson_insitu)->UseManualTime(); } // namespace kostya diff --git a/benchmark/kostya/simdjson_dom.h b/benchmark/kostya/simdjson_dom.h index cd8d69bb3..e5ac15d24 100644 --- a/benchmark/kostya/simdjson_dom.h +++ b/benchmark/kostya/simdjson_dom.h @@ -19,7 +19,7 @@ struct simdjson_dom { } }; -BENCHMARK_TEMPLATE(kostya, simdjson_dom); +BENCHMARK_TEMPLATE(kostya, simdjson_dom)->UseManualTime(); } // namespace kostya diff --git a/benchmark/kostya/simdjson_ondemand.h b/benchmark/kostya/simdjson_ondemand.h index 797ca3a1e..2c463050f 100644 --- a/benchmark/kostya/simdjson_ondemand.h +++ b/benchmark/kostya/simdjson_ondemand.h @@ -21,7 +21,7 @@ struct simdjson_ondemand { } }; -BENCHMARK_TEMPLATE(kostya, simdjson_ondemand); +BENCHMARK_TEMPLATE(kostya, simdjson_ondemand)->UseManualTime(); } // namespace kostya diff --git a/benchmark/kostya/yyjson.h b/benchmark/kostya/yyjson.h index e9f353885..a9ba4be43 100644 --- a/benchmark/kostya/yyjson.h +++ b/benchmark/kostya/yyjson.h @@ -44,7 +44,7 @@ struct yyjson { }; -BENCHMARK_TEMPLATE(kostya, yyjson); +BENCHMARK_TEMPLATE(kostya, yyjson)->UseManualTime(); } // namespace kostya diff --git a/benchmark/large_random/rapidjson.h b/benchmark/large_random/rapidjson.h index 2a2d4694f..58a12f820 100644 --- a/benchmark/large_random/rapidjson.h +++ b/benchmark/large_random/rapidjson.h @@ -35,14 +35,14 @@ struct rapidjson : public rapidjson_base { return rapidjson_base::run(doc.Parse(json.data()), points); } }; -BENCHMARK_TEMPLATE(large_random, rapidjson); +BENCHMARK_TEMPLATE(large_random, rapidjson)->UseManualTime(); struct rapidjson_lossless : public rapidjson_base { bool run(const simdjson::padded_string &json, std::vector &points) { return rapidjson_base::run(doc.Parse(json.data()), points); } }; -BENCHMARK_TEMPLATE(large_random, rapidjson_lossless); +BENCHMARK_TEMPLATE(large_random, rapidjson_lossless)->UseManualTime(); struct rapidjson_insitu : public rapidjson_base { bool run(const simdjson::padded_string &json, std::vector &points) { @@ -50,7 +50,7 @@ struct rapidjson_insitu : public rapidjson_base { return rapidjson_base::run(doc.ParseInsitu(json_copy.data()), points); } }; -BENCHMARK_TEMPLATE(large_random, rapidjson_insitu); +BENCHMARK_TEMPLATE(large_random, rapidjson_insitu)->UseManualTime(); } // namespace large_random diff --git a/benchmark/large_random/simdjson_dom.h b/benchmark/large_random/simdjson_dom.h index 4fcd49a98..d88e84eb1 100644 --- a/benchmark/large_random/simdjson_dom.h +++ b/benchmark/large_random/simdjson_dom.h @@ -19,7 +19,7 @@ struct simdjson_dom { } }; -BENCHMARK_TEMPLATE(large_random, simdjson_dom); +BENCHMARK_TEMPLATE(large_random, simdjson_dom)->UseManualTime(); } // namespace large_random diff --git a/benchmark/large_random/simdjson_ondemand.h b/benchmark/large_random/simdjson_ondemand.h index ac4c1a777..a2e7c0e52 100644 --- a/benchmark/large_random/simdjson_ondemand.h +++ b/benchmark/large_random/simdjson_ondemand.h @@ -21,7 +21,7 @@ struct simdjson_ondemand { } }; -BENCHMARK_TEMPLATE(large_random, simdjson_ondemand); +BENCHMARK_TEMPLATE(large_random, simdjson_ondemand)->UseManualTime(); } // namespace large_random diff --git a/benchmark/large_random/simdjson_ondemand_unordered.h b/benchmark/large_random/simdjson_ondemand_unordered.h index e5e55ef05..c77014271 100644 --- a/benchmark/large_random/simdjson_ondemand_unordered.h +++ b/benchmark/large_random/simdjson_ondemand_unordered.h @@ -21,7 +21,7 @@ struct simdjson_ondemand_unordered { } }; -BENCHMARK_TEMPLATE(large_random, simdjson_ondemand_unordered); +BENCHMARK_TEMPLATE(large_random, simdjson_ondemand_unordered)->UseManualTime(); } // namespace large_random diff --git a/benchmark/large_random/yyjson.h b/benchmark/large_random/yyjson.h index 995a61ca1..61dbb3c53 100644 --- a/benchmark/large_random/yyjson.h +++ b/benchmark/large_random/yyjson.h @@ -41,7 +41,7 @@ struct yyjson { } }; -BENCHMARK_TEMPLATE(large_random, yyjson); +BENCHMARK_TEMPLATE(large_random, yyjson)->UseManualTime(); } // namespace large_random diff --git a/benchmark/partial_tweets/rapidjson.h b/benchmark/partial_tweets/rapidjson.h index b0862de88..b9b702f1e 100644 --- a/benchmark/partial_tweets/rapidjson.h +++ b/benchmark/partial_tweets/rapidjson.h @@ -64,16 +64,15 @@ struct rapidjson : public rapidjson_base { return rapidjson_base::run(doc.Parse(json.data()), tweets); } }; -BENCHMARK_TEMPLATE(partial_tweets, rapidjson); +BENCHMARK_TEMPLATE(partial_tweets, rapidjson)->UseManualTime(); // TODO this fails! // struct rapidjson_insitu : public rapidjson_base { -// bool run(const padded_string &json, std::vector &tweets) { -// padded_string json_copy{json.data(), json.size()}; -// return rapidjson_base::run(doc.ParseInsitu(json_copy.data()), tweets); +// bool run(simdjson::padded_string &json, std::vector &tweets) { +// return rapidjson_base::run(doc.ParseInsitu(json.data()), tweets); // } // }; -// BENCHMARK_TEMPLATE(partial_tweets, rapidjson_insitu); +// BENCHMARK_TEMPLATE(partial_tweets, rapidjson_insitu)->UseManualTime(); } // namespace partial_tweets diff --git a/benchmark/partial_tweets/simdjson_dom.h b/benchmark/partial_tweets/simdjson_dom.h index 5920a34a5..ef5849b9f 100644 --- a/benchmark/partial_tweets/simdjson_dom.h +++ b/benchmark/partial_tweets/simdjson_dom.h @@ -34,7 +34,7 @@ struct simdjson_dom { } }; -BENCHMARK_TEMPLATE(partial_tweets, simdjson_dom); +BENCHMARK_TEMPLATE(partial_tweets, simdjson_dom)->UseManualTime(); } // namespace partial_tweets diff --git a/benchmark/partial_tweets/simdjson_ondemand.h b/benchmark/partial_tweets/simdjson_ondemand.h index aed3c22b3..ac744d433 100644 --- a/benchmark/partial_tweets/simdjson_ondemand.h +++ b/benchmark/partial_tweets/simdjson_ondemand.h @@ -40,7 +40,7 @@ struct simdjson_ondemand { } }; -BENCHMARK_TEMPLATE(partial_tweets, simdjson_ondemand); +BENCHMARK_TEMPLATE(partial_tweets, simdjson_ondemand)->UseManualTime(); } // namespace partial_tweets diff --git a/benchmark/partial_tweets/yyjson.h b/benchmark/partial_tweets/yyjson.h index fe0db0d77..3b3a3d337 100644 --- a/benchmark/partial_tweets/yyjson.h +++ b/benchmark/partial_tweets/yyjson.h @@ -59,7 +59,7 @@ struct yyjson { } }; -BENCHMARK_TEMPLATE(partial_tweets, yyjson); +BENCHMARK_TEMPLATE(partial_tweets, yyjson)->UseManualTime(); } // namespace partial_tweets