diff --git a/benchmark/bench_dom_api.cpp b/benchmark/bench_dom_api.cpp index 37a414531..25efaef59 100644 --- a/benchmark/bench_dom_api.cpp +++ b/benchmark/bench_dom_api.cpp @@ -365,7 +365,8 @@ BENCHMARK(twitter_image_sizes); static void error_code_twitter_count(State& state) noexcept { // Prints the number of results in twitter.json dom::parser parser; - dom::element doc = parser.load(TWITTER_JSON); + auto [doc, error1] = parser.load(TWITTER_JSON); + if (error1) { return; } for (UNUSED auto _ : state) { auto [value, error] = doc["search_metadata"]["count"].get(); if (error) { return; } @@ -377,7 +378,8 @@ BENCHMARK(error_code_twitter_count); static void error_code_twitter_default_profile(State& state) noexcept { // Count unique users with a default profile. dom::parser parser; - dom::element doc = parser.load(TWITTER_JSON); + auto [doc, error1] = parser.load(TWITTER_JSON); + if (error1) { std::cerr << error1 << std::endl; return; } for (UNUSED auto _ : state) { set default_users; @@ -404,7 +406,8 @@ SIMDJSON_PUSH_DISABLE_WARNINGS SIMDJSON_DISABLE_DEPRECATED_WARNING static void iterator_twitter_default_profile(State& state) { // Count unique users with a default profile. - padded_string json = padded_string::load(TWITTER_JSON); + auto [json, error1] = padded_string::load(TWITTER_JSON); + if (error1) { std::cerr << error1 << std::endl; return; } ParsedJson pj = build_parsed_json(json); for (UNUSED auto _ : state) { set default_users; @@ -444,7 +447,8 @@ BENCHMARK(iterator_twitter_default_profile); static void error_code_twitter_image_sizes(State& state) noexcept { // Count unique image sizes dom::parser parser; - dom::element doc = parser.load(TWITTER_JSON); + auto [doc, error1] = parser.load(TWITTER_JSON); + if (error1) { std::cerr << error1 << std::endl; return; } for (UNUSED auto _ : state) { set> image_sizes; auto [statuses, error] = doc["statuses"].get(); @@ -473,7 +477,8 @@ SIMDJSON_PUSH_DISABLE_WARNINGS SIMDJSON_DISABLE_DEPRECATED_WARNING static void iterator_twitter_image_sizes(State& state) { // Count unique image sizes - padded_string json = padded_string::load(TWITTER_JSON); + auto [json, error1] = padded_string::load(TWITTER_JSON); + if (error1) { std::cerr << error1 << std::endl; return; } ParsedJson pj = build_parsed_json(json); for (UNUSED auto _ : state) { set> image_sizes; @@ -531,7 +536,8 @@ BENCHMARK(iterator_twitter_image_sizes); static void print_json(State& state) noexcept { // Prints the number of results in twitter.json - padded_string json = get_corpus(TWITTER_JSON); + auto [json, error1] = padded_string::load(TWITTER_JSON); + if (error1) { std::cerr << error1 << std::endl; return; } dom::parser parser; if (int error = json_parse(json, parser); error != SUCCESS) { cerr << error_message(error) << endl; return; } for (UNUSED auto _ : state) { diff --git a/benchmark/bench_parse_call.cpp b/benchmark/bench_parse_call.cpp index deb1e4a7d..484ffc9fd 100644 --- a/benchmark/bench_parse_call.cpp +++ b/benchmark/bench_parse_call.cpp @@ -104,6 +104,9 @@ static void parser_parse_error_code(State& state) { } } BENCHMARK(parser_parse_error_code); + +#if SIMDJSON_EXCEPTIONS + static void parser_parse_exception(State& state) { dom::parser parser; if (parser.allocate(EMPTY_ARRAY.length())) { return; } @@ -118,6 +121,8 @@ static void parser_parse_exception(State& state) { } BENCHMARK(parser_parse_exception); +#endif // SIMDJSON_EXCEPTIONS + SIMDJSON_PUSH_DISABLE_WARNINGS SIMDJSON_DISABLE_DEPRECATED_WARNING static void build_parsed_json(State& state) { @@ -127,6 +132,7 @@ static void build_parsed_json(State& state) { } } SIMDJSON_POP_DISABLE_WARNINGS + BENCHMARK(build_parsed_json); static void document_parse_error_code(State& state) { for (UNUSED auto _ : state) { @@ -136,6 +142,9 @@ static void document_parse_error_code(State& state) { } } BENCHMARK(document_parse_error_code); + +#if SIMDJSON_EXCEPTIONS + static void document_parse_exception(State& state) { for (UNUSED auto _ : state) { try { @@ -149,4 +158,6 @@ static void document_parse_exception(State& state) { } BENCHMARK(document_parse_exception); +#endif // SIMDJSON_EXCEPTIONS + BENCHMARK_MAIN(); \ No newline at end of file diff --git a/simdjson-flags.cmake b/simdjson-flags.cmake index c2d308083..73a2a8896 100644 --- a/simdjson-flags.cmake +++ b/simdjson-flags.cmake @@ -11,7 +11,7 @@ else() option(SIMDJSON_COMPETITION "Compile competitive benchmarks" ON) option(SIMDJSON_USE_LIBCPP "Use the libc++ library" OFF) endif() -option(SIMDJSON_GOOGLE_BENCHMARKS "compile the Google Benchmark benchmarks" OFF) +option(SIMDJSON_GOOGLE_BENCHMARKS "compile the Google Benchmark benchmarks" ON) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake")