From dfc510f009cc62b9f5452fc5981c514c03984952 Mon Sep 17 00:00:00 2001 From: John Keiser Date: Sun, 20 Dec 2020 10:19:12 -0800 Subject: [PATCH] Add bench_ondemand_largerandom to check theory about executable format --- benchmark/CMakeLists.txt | 5 ++- benchmark/largerandom/CMakeLists.txt | 4 ++ .../bench_ondemand_largerandom.cpp | 14 +++++++ benchmark/largerandom/dom.h | 32 --------------- benchmark/largerandom/iter.h | 39 ------------------- benchmark/largerandom/largerandom.h | 16 +++----- benchmark/largerandom/ondemand.h | 33 ---------------- 7 files changed, 28 insertions(+), 115 deletions(-) create mode 100644 benchmark/largerandom/CMakeLists.txt create mode 100644 benchmark/largerandom/bench_ondemand_largerandom.cpp diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index f15c73ff..b3c796b2 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -1,13 +1,15 @@ include_directories( . linux ) link_libraries(simdjson-windows-headers test-data) - +# bench_sax links against the source if (TARGET benchmark::benchmark) add_executable(bench_sax bench_sax.cpp) target_link_libraries(bench_sax PRIVATE simdjson-internal-flags simdjson-include-source benchmark::benchmark) endif (TARGET benchmark::benchmark) +# Everything else links against simdjson proper link_libraries(simdjson simdjson-flags) + add_executable(benchfeatures benchfeatures.cpp) add_executable(get_corpus_benchmark get_corpus_benchmark.cpp) add_executable(perfdiff perfdiff.cpp) @@ -42,6 +44,7 @@ endif() if (TARGET benchmark::benchmark) link_libraries(benchmark::benchmark) + add_subdirectory(largerandom) add_executable(bench_parse_call bench_parse_call.cpp) add_executable(bench_dom_api bench_dom_api.cpp) add_executable(bench_ondemand bench_ondemand.cpp) diff --git a/benchmark/largerandom/CMakeLists.txt b/benchmark/largerandom/CMakeLists.txt new file mode 100644 index 00000000..f537b0e7 --- /dev/null +++ b/benchmark/largerandom/CMakeLists.txt @@ -0,0 +1,4 @@ +if (TARGET benchmark::benchmark) + link_libraries(benchmark::benchmark) + add_executable(bench_ondemand_largerandom bench_ondemand_largerandom.cpp) +endif() diff --git a/benchmark/largerandom/bench_ondemand_largerandom.cpp b/benchmark/largerandom/bench_ondemand_largerandom.cpp new file mode 100644 index 00000000..e1f35f6b --- /dev/null +++ b/benchmark/largerandom/bench_ondemand_largerandom.cpp @@ -0,0 +1,14 @@ +#include "simdjson.h" +#include +#include +#include +#include +SIMDJSON_PUSH_DISABLE_ALL_WARNINGS +#include +SIMDJSON_POP_DISABLE_WARNINGS + +#define BENCHMARK_NO_DOM + +#include "largerandom/ondemand.h" + +BENCHMARK_MAIN(); diff --git a/benchmark/largerandom/dom.h b/benchmark/largerandom/dom.h index 4148eeee..a2642c04 100644 --- a/benchmark/largerandom/dom.h +++ b/benchmark/largerandom/dom.h @@ -32,38 +32,6 @@ simdjson_really_inline bool Dom::Run(const padded_string &json) { BENCHMARK_TEMPLATE(LargeRandom, Dom); -namespace sum { - -class Dom { -public: - simdjson_really_inline bool Run(const padded_string &json); - - simdjson_really_inline my_point &Result() { return sum; } - simdjson_really_inline size_t ItemCount() { return count; } - -private: - dom::parser parser{}; - my_point sum{}; - size_t count{}; -}; - -simdjson_really_inline bool Dom::Run(const padded_string &json) { - sum = { 0, 0, 0 }; - count = 0; - - for (auto coord : parser.parse(json)) { - sum.x += double(coord["x"]); - sum.y += double(coord["y"]); - sum.z += double(coord["z"]); - count++; - } - - return true; -} - -BENCHMARK_TEMPLATE(LargeRandomSum, Dom); - -} // namespace sum } // namespace largerandom #endif // SIMDJSON_EXCEPTIONS \ No newline at end of file diff --git a/benchmark/largerandom/iter.h b/benchmark/largerandom/iter.h index 10ab2354..bb4b2cb8 100644 --- a/benchmark/largerandom/iter.h +++ b/benchmark/largerandom/iter.h @@ -48,45 +48,6 @@ simdjson_really_inline bool Iter::Run(const padded_string &json) { BENCHMARK_TEMPLATE(LargeRandom, Iter); - -namespace sum { - -class Iter { -public: - simdjson_really_inline bool Run(const padded_string &json); - - simdjson_really_inline my_point &Result() { return sum; } - simdjson_really_inline size_t ItemCount() { return count; } - -private: - ondemand::parser parser{}; - my_point sum{}; - size_t count{}; -}; - -simdjson_really_inline bool Iter::Run(const padded_string &json) { - sum = {0,0,0}; - count = 0; - - auto iter = parser.iterate_raw(json).value(); - if (!iter.start_array()) { return false; } - do { - if (!iter.start_object() || iter.field_key().value() != "x" || iter.field_value()) { return false; } - sum.x += iter.consume_double(); - if (!iter.has_next_field() || iter.field_key().value() != "y" || iter.field_value()) { return false; } - sum.y += iter.consume_double(); - if (!iter.has_next_field() || iter.field_key().value() != "z" || iter.field_value()) { return false; } - sum.z += iter.consume_double(); - if (*iter.advance() != '}') { return false; } - count++; - } while (iter.has_next_element()); - - return true; -} - -BENCHMARK_TEMPLATE(LargeRandomSum, Iter); - -} // namespace sum } // namespace largerandom #endif // SIMDJSON_EXCEPTIONS diff --git a/benchmark/largerandom/largerandom.h b/benchmark/largerandom/largerandom.h index c8bf3d7a..e7fc6d5a 100644 --- a/benchmark/largerandom/largerandom.h +++ b/benchmark/largerandom/largerandom.h @@ -8,9 +8,6 @@ namespace largerandom { template static void LargeRandom(benchmark::State &state); -namespace sum { -template static void LargeRandomSum(benchmark::State &state); -} using namespace simdjson; @@ -59,22 +56,21 @@ simdjson_unused static std::ostream &operator<<(std::ostream &o, const my_point // #include #include "event_counter.h" +#ifndef BENCHMARK_NO_DOM #include "dom.h" +#endif #include "json_benchmark.h" namespace largerandom { template static void LargeRandom(benchmark::State &state) { +#ifdef BENCHMARK_NO_DOM + JsonBenchmark(state, get_built_json_array()); +#else JsonBenchmark(state, get_built_json_array()); +#endif } -namespace sum { - -template static void LargeRandomSum(benchmark::State &state) { - JsonBenchmark(state, get_built_json_array()); -} - -} } // namespace largerandom #endif // SIMDJSON_EXCEPTIONS diff --git a/benchmark/largerandom/ondemand.h b/benchmark/largerandom/ondemand.h index 4151e311..f3b5fcaa 100644 --- a/benchmark/largerandom/ondemand.h +++ b/benchmark/largerandom/ondemand.h @@ -33,39 +33,6 @@ simdjson_really_inline bool OnDemand::Run(const padded_string &json) { BENCHMARK_TEMPLATE(LargeRandom, OnDemand); - -namespace sum { - -class OnDemand { -public: - simdjson_really_inline bool Run(const padded_string &json); - simdjson_really_inline my_point &Result() { return sum; } - simdjson_really_inline size_t ItemCount() { return count; } - -private: - ondemand::parser parser{}; - my_point sum{}; - size_t count{}; -}; - -simdjson_really_inline bool OnDemand::Run(const padded_string &json) { - sum = {0,0,0}; - count = 0; - - auto doc = parser.iterate(json); - for (ondemand::object coord : doc.get_array()) { - sum.x += double(coord.find_field("x")); - sum.y += double(coord.find_field("y")); - sum.z += double(coord.find_field("z")); - count++; - } - - return true; -} - -BENCHMARK_TEMPLATE(LargeRandomSum, OnDemand); - -} // namespace sum } // namespace largerandom #endif // SIMDJSON_EXCEPTIONS