diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
commit | e6918187568dbd01842d8d1d2c808ce16a894239 (patch) | |
tree | 64f88b554b444a49f656b6c656111a145cbbaa28 /src/jaegertracing/opentelemetry-cpp/third_party/nlohmann-json/benchmarks | |
parent | Initial commit. (diff) | |
download | ceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip |
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/jaegertracing/opentelemetry-cpp/third_party/nlohmann-json/benchmarks')
2 files changed, 143 insertions, 0 deletions
diff --git a/src/jaegertracing/opentelemetry-cpp/third_party/nlohmann-json/benchmarks/CMakeLists.txt b/src/jaegertracing/opentelemetry-cpp/third_party/nlohmann-json/benchmarks/CMakeLists.txt new file mode 100644 index 000000000..1243f54ea --- /dev/null +++ b/src/jaegertracing/opentelemetry-cpp/third_party/nlohmann-json/benchmarks/CMakeLists.txt @@ -0,0 +1,33 @@ +cmake_minimum_required(VERSION 3.11) +project(JSON_Benchmarks LANGUAGES CXX) + +# set compiler flags +if((CMAKE_CXX_COMPILER_ID MATCHES GNU) OR (CMAKE_CXX_COMPILER_ID MATCHES Clang)) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto -DNDEBUG -O3") +endif() + +# configure Google Benchmarks +include(FetchContent) +FetchContent_Declare( + benchmark + GIT_REPOSITORY https://github.com/google/benchmark.git + GIT_TAG origin/main + GIT_SHALLOW TRUE +) + +FetchContent_GetProperties(benchmark) +if(NOT benchmark_POPULATED) + FetchContent_Populate(benchmark) + set(BENCHMARK_ENABLE_TESTING OFF CACHE INTERNAL "" FORCE) + add_subdirectory(${benchmark_SOURCE_DIR} ${benchmark_BINARY_DIR}) +endif() + +# download test data +include(${CMAKE_SOURCE_DIR}/../cmake/download_test_data.cmake) + +# benchmark binary +add_executable(json_benchmarks src/benchmarks.cpp) +target_compile_features(json_benchmarks PRIVATE cxx_std_11) +target_link_libraries(json_benchmarks benchmark ${CMAKE_THREAD_LIBS_INIT}) +add_dependencies(json_benchmarks download_test_data) +target_include_directories(json_benchmarks PRIVATE ${CMAKE_SOURCE_DIR}/../single_include ${CMAKE_BINARY_DIR}/include) diff --git a/src/jaegertracing/opentelemetry-cpp/third_party/nlohmann-json/benchmarks/src/benchmarks.cpp b/src/jaegertracing/opentelemetry-cpp/third_party/nlohmann-json/benchmarks/src/benchmarks.cpp new file mode 100644 index 000000000..4f32a61a2 --- /dev/null +++ b/src/jaegertracing/opentelemetry-cpp/third_party/nlohmann-json/benchmarks/src/benchmarks.cpp @@ -0,0 +1,110 @@ +#include "benchmark/benchmark.h" +#include <nlohmann/json.hpp> +#include <fstream> +#include <test_data.hpp> + +using json = nlohmann::json; + +////////////////////////////////////////////////////////////////////////////// +// parse JSON from file +////////////////////////////////////////////////////////////////////////////// + +static void ParseFile(benchmark::State& state, const char* filename) +{ + while (state.KeepRunning()) + { + state.PauseTiming(); + auto* f = new std::ifstream(filename); + auto* j = new json(); + state.ResumeTiming(); + + *j = json::parse(*f); + + state.PauseTiming(); + delete f; + delete j; + state.ResumeTiming(); + } + + std::ifstream file(filename, std::ios::binary | std::ios::ate); + state.SetBytesProcessed(state.iterations() * file.tellg()); +} +BENCHMARK_CAPTURE(ParseFile, jeopardy, TEST_DATA_DIRECTORY "/jeopardy/jeopardy.json"); +BENCHMARK_CAPTURE(ParseFile, canada, TEST_DATA_DIRECTORY "/nativejson-benchmark/canada.json"); +BENCHMARK_CAPTURE(ParseFile, citm_catalog, TEST_DATA_DIRECTORY "/nativejson-benchmark/citm_catalog.json"); +BENCHMARK_CAPTURE(ParseFile, twitter, TEST_DATA_DIRECTORY "/nativejson-benchmark/twitter.json"); +BENCHMARK_CAPTURE(ParseFile, floats, TEST_DATA_DIRECTORY "/regression/floats.json"); +BENCHMARK_CAPTURE(ParseFile, signed_ints, TEST_DATA_DIRECTORY "/regression/signed_ints.json"); +BENCHMARK_CAPTURE(ParseFile, unsigned_ints, TEST_DATA_DIRECTORY "/regression/unsigned_ints.json"); +BENCHMARK_CAPTURE(ParseFile, small_signed_ints, TEST_DATA_DIRECTORY "/regression/small_signed_ints.json"); + +////////////////////////////////////////////////////////////////////////////// +// parse JSON from string +////////////////////////////////////////////////////////////////////////////// + +static void ParseString(benchmark::State& state, const char* filename) +{ + std::ifstream f(filename); + std::string str((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>()); + + while (state.KeepRunning()) + { + state.PauseTiming(); + auto* j = new json(); + state.ResumeTiming(); + + *j = json::parse(str); + + state.PauseTiming(); + delete j; + state.ResumeTiming(); + } + + state.SetBytesProcessed(state.iterations() * str.size()); +} +BENCHMARK_CAPTURE(ParseString, jeopardy, TEST_DATA_DIRECTORY "/jeopardy/jeopardy.json"); +BENCHMARK_CAPTURE(ParseString, canada, TEST_DATA_DIRECTORY "/nativejson-benchmark/canada.json"); +BENCHMARK_CAPTURE(ParseString, citm_catalog, TEST_DATA_DIRECTORY "/nativejson-benchmark/citm_catalog.json"); +BENCHMARK_CAPTURE(ParseString, twitter, TEST_DATA_DIRECTORY "/nativejson-benchmark/twitter.json"); +BENCHMARK_CAPTURE(ParseString, floats, TEST_DATA_DIRECTORY "/regression/floats.json"); +BENCHMARK_CAPTURE(ParseString, signed_ints, TEST_DATA_DIRECTORY "/regression/signed_ints.json"); +BENCHMARK_CAPTURE(ParseString, unsigned_ints, TEST_DATA_DIRECTORY "/regression/unsigned_ints.json"); +BENCHMARK_CAPTURE(ParseString, small_signed_ints, TEST_DATA_DIRECTORY "/regression/small_signed_ints.json"); + + +////////////////////////////////////////////////////////////////////////////// +// serialize JSON +////////////////////////////////////////////////////////////////////////////// + +static void Dump(benchmark::State& state, const char* filename, int indent) +{ + std::ifstream f(filename); + std::string str((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>()); + json j = json::parse(str); + + while (state.KeepRunning()) + { + j.dump(indent); + } + + state.SetBytesProcessed(state.iterations() * j.dump(indent).size()); +} +BENCHMARK_CAPTURE(Dump, jeopardy / -, TEST_DATA_DIRECTORY "/jeopardy/jeopardy.json", -1); +BENCHMARK_CAPTURE(Dump, jeopardy / 4, TEST_DATA_DIRECTORY "/jeopardy/jeopardy.json", 4); +BENCHMARK_CAPTURE(Dump, canada / -, TEST_DATA_DIRECTORY "/nativejson-benchmark/canada.json", -1); +BENCHMARK_CAPTURE(Dump, canada / 4, TEST_DATA_DIRECTORY "/nativejson-benchmark/canada.json", 4); +BENCHMARK_CAPTURE(Dump, citm_catalog / -, TEST_DATA_DIRECTORY "/nativejson-benchmark/citm_catalog.json", -1); +BENCHMARK_CAPTURE(Dump, citm_catalog / 4, TEST_DATA_DIRECTORY "/nativejson-benchmark/citm_catalog.json", 4); +BENCHMARK_CAPTURE(Dump, twitter / -, TEST_DATA_DIRECTORY "/nativejson-benchmark/twitter.json", -1); +BENCHMARK_CAPTURE(Dump, twitter / 4, TEST_DATA_DIRECTORY "/nativejson-benchmark/twitter.json", 4); +BENCHMARK_CAPTURE(Dump, floats / -, TEST_DATA_DIRECTORY "/regression/floats.json", -1); +BENCHMARK_CAPTURE(Dump, floats / 4, TEST_DATA_DIRECTORY "/regression/floats.json", 4); +BENCHMARK_CAPTURE(Dump, signed_ints / -, TEST_DATA_DIRECTORY "/regression/signed_ints.json", -1); +BENCHMARK_CAPTURE(Dump, signed_ints / 4, TEST_DATA_DIRECTORY "/regression/signed_ints.json", 4); +BENCHMARK_CAPTURE(Dump, unsigned_ints / -, TEST_DATA_DIRECTORY "/regression/unsigned_ints.json", -1); +BENCHMARK_CAPTURE(Dump, unsigned_ints / 4, TEST_DATA_DIRECTORY "/regression/unsigned_ints.json", 4); +BENCHMARK_CAPTURE(Dump, small_signed_ints / -, TEST_DATA_DIRECTORY "/regression/small_signed_ints.json", -1); +BENCHMARK_CAPTURE(Dump, small_signed_ints / 4, TEST_DATA_DIRECTORY "/regression/small_signed_ints.json", 4); + + +BENCHMARK_MAIN(); |