From 3039212b509cdb83c8d4d19e7a6a1efd3e7027a5 Mon Sep 17 00:00:00 2001 From: liuzicheng1987 Date: Thu, 6 Jun 2024 20:44:22 +0200 Subject: [PATCH] Added all format benchmarks for the person dataset (#114) --- .github/workflows/linux-clang.yaml | 4 +- .github/workflows/linux-gcc.yaml | 4 +- .github/workflows/macos-clang-arm.yaml | 4 +- .github/workflows/macos-clang-x64.yaml | 4 +- .github/workflows/windows-msvc.yaml | 4 +- benchmarks/all/person_read.cpp | 136 ++++++++++++++++++ benchmarks/all/person_write.cpp | 136 ++++++++++++++++++ .../json/{simple_read.cpp => person.cpp} | 24 ++-- 8 files changed, 299 insertions(+), 17 deletions(-) create mode 100644 benchmarks/all/person_read.cpp create mode 100644 benchmarks/all/person_write.cpp rename benchmarks/json/{simple_read.cpp => person.cpp} (93%) diff --git a/.github/workflows/linux-clang.yaml b/.github/workflows/linux-clang.yaml index e65fd6c5..a65e2d6d 100644 --- a/.github/workflows/linux-clang.yaml +++ b/.github/workflows/linux-clang.yaml @@ -42,8 +42,10 @@ jobs: - name: Run benchmarks run: | ./build/benchmarks/json/reflect-cpp-json-benchmarks --benchmark_filter=canada - ./build/benchmarks/json/reflect-cpp-json-benchmarks --benchmark_filter=simple_read + ./build/benchmarks/json/reflect-cpp-json-benchmarks --benchmark_filter=person_read ./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=canada_read ./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=canada_write ./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=licenses_read ./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=licenses_write + ./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=person_read + ./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=person_write diff --git a/.github/workflows/linux-gcc.yaml b/.github/workflows/linux-gcc.yaml index 2aa57f46..cb1e8721 100644 --- a/.github/workflows/linux-gcc.yaml +++ b/.github/workflows/linux-gcc.yaml @@ -35,8 +35,10 @@ jobs: - name: Run benchmarks run: | ./build/benchmarks/json/reflect-cpp-json-benchmarks --benchmark_filter=canada - ./build/benchmarks/json/reflect-cpp-json-benchmarks --benchmark_filter=simple_read + ./build/benchmarks/json/reflect-cpp-json-benchmarks --benchmark_filter=person_read ./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=canada_read ./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=canada_write ./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=licenses_read ./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=licenses_write + ./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=person_read + ./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=person_write diff --git a/.github/workflows/macos-clang-arm.yaml b/.github/workflows/macos-clang-arm.yaml index 83fc4634..dd4b05be 100644 --- a/.github/workflows/macos-clang-arm.yaml +++ b/.github/workflows/macos-clang-arm.yaml @@ -37,8 +37,10 @@ jobs: - name: Run benchmarks run: | ./build/benchmarks/json/reflect-cpp-json-benchmarks --benchmark_filter=canada - ./build/benchmarks/json/reflect-cpp-json-benchmarks --benchmark_filter=simple_read + ./build/benchmarks/json/reflect-cpp-json-benchmarks --benchmark_filter=person_read ./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=canada_read ./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=canada_write ./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=licenses_read ./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=licenses_write + ./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=person_read + ./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=person_write diff --git a/.github/workflows/macos-clang-x64.yaml b/.github/workflows/macos-clang-x64.yaml index c058b8d2..8934701f 100644 --- a/.github/workflows/macos-clang-x64.yaml +++ b/.github/workflows/macos-clang-x64.yaml @@ -34,8 +34,10 @@ jobs: - name: Run benchmarks run: | ./build/benchmarks/json/reflect-cpp-json-benchmarks --benchmark_filter=canada - ./build/benchmarks/json/reflect-cpp-json-benchmarks --benchmark_filter=simple_read + ./build/benchmarks/json/reflect-cpp-json-benchmarks --benchmark_filter=person_read ./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=canada_read ./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=canada_write ./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=licenses_read ./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=licenses_write + ./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=person_read + ./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=person_write diff --git a/.github/workflows/windows-msvc.yaml b/.github/workflows/windows-msvc.yaml index 8ab724bb..bd5917d2 100644 --- a/.github/workflows/windows-msvc.yaml +++ b/.github/workflows/windows-msvc.yaml @@ -30,8 +30,10 @@ jobs: - name: Run benchmarks run: | .\build\benchmarks\json\Release\reflect-cpp-json-benchmarks.exe --benchmark_filter=canada - .\build\benchmarks\json\Release\reflect-cpp-json-benchmarks.exe --benchmark_filter=simple_read + .\build\benchmarks\json\Release\reflect-cpp-json-benchmarks.exe --benchmark_filter=person_read .\build\benchmarks\all\Release\reflect-cpp-all-format-benchmarks.exe --benchmark_filter=canada_read .\build\benchmarks\all\Release\reflect-cpp-all-format-benchmarks.exe --benchmark_filter=canada_write .\build\benchmarks\all\Release\reflect-cpp-all-format-benchmarks.exe --benchmark_filter=licenses_read .\build\benchmarks\all\Release\reflect-cpp-all-format-benchmarks.exe --benchmark_filter=licenses_write + .\build\benchmarks\all\Release\reflect-cpp-all-format-benchmarks.exe --benchmark_filter=person_read + .\build\benchmarks\all\Release\reflect-cpp-all-format-benchmarks.exe --benchmark_filter=person_write diff --git a/benchmarks/all/person_read.cpp b/benchmarks/all/person_read.cpp new file mode 100644 index 00000000..3649bbd6 --- /dev/null +++ b/benchmarks/all/person_read.cpp @@ -0,0 +1,136 @@ +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace person_read { + +// ---------------------------------------------------------------------------- + +struct Person { + std::string first_name; + std::string last_name = "Simpson"; + int age; + std::string town = "Springfield"; + std::vector children; +}; + +// ---------------------------------------------------------------------------- + +static Person load_data() { + const auto bart = Person{.first_name = "Bart", .age = 10}; + + const auto lisa = Person{.first_name = "Lisa", .age = 8}; + + const auto maggie = Person{.first_name = "Maggie", .age = 0}; + + return Person{.first_name = "Homer", + .age = 45, + .children = std::vector({bart, lisa, maggie})}; +} + +// ---------------------------------------------------------------------------- + +static void BM_person_read_reflect_cpp_bson(benchmark::State &state) { + const auto data = rfl::bson::write(load_data()); + for (auto _ : state) { + const auto res = rfl::bson::read(data); + if (!res) { + std::cout << res.error()->what() << std::endl; + } + } +} +BENCHMARK(BM_person_read_reflect_cpp_bson); + +static void BM_person_read_reflect_cpp_cbor(benchmark::State &state) { + const auto data = rfl::cbor::write(load_data()); + for (auto _ : state) { + const auto res = rfl::cbor::read(data); + if (!res) { + std::cout << res.error()->what() << std::endl; + } + } +} +BENCHMARK(BM_person_read_reflect_cpp_cbor); + +static void BM_person_read_reflect_cpp_flexbuf(benchmark::State &state) { + const auto data = rfl::flexbuf::write(load_data()); + for (auto _ : state) { + const auto res = rfl::flexbuf::read(data); + if (!res) { + std::cout << res.error()->what() << std::endl; + } + } +} +BENCHMARK(BM_person_read_reflect_cpp_flexbuf); + +static void BM_person_read_reflect_cpp_json(benchmark::State &state) { + const auto data = rfl::json::write(load_data()); + for (auto _ : state) { + const auto res = rfl::json::read(data); + if (!res) { + std::cout << res.error()->what() << std::endl; + } + } +} +BENCHMARK(BM_person_read_reflect_cpp_json); + +static void BM_person_read_reflect_cpp_msgpack(benchmark::State &state) { + const auto data = rfl::msgpack::write(load_data()); + for (auto _ : state) { + const auto res = rfl::msgpack::read(data); + if (!res) { + std::cout << res.error()->what() << std::endl; + } + } +} +BENCHMARK(BM_person_read_reflect_cpp_msgpack); + +static void BM_person_read_reflect_cpp_toml(benchmark::State &state) { + const auto data = rfl::toml::write(load_data()); + for (auto _ : state) { + const auto res = rfl::toml::read(data); + if (!res) { + std::cout << res.error()->what() << std::endl; + } + } +} +BENCHMARK(BM_person_read_reflect_cpp_toml); + +static void BM_person_read_reflect_cpp_xml(benchmark::State &state) { + const auto data = rfl::xml::write(load_data()); + for (auto _ : state) { + const auto res = rfl::xml::read(data); + if (!res) { + std::cout << res.error()->what() << std::endl; + } + } +} +BENCHMARK(BM_person_read_reflect_cpp_xml); + +static void BM_person_read_reflect_cpp_yaml(benchmark::State &state) { + const auto data = rfl::yaml::write(load_data()); + for (auto _ : state) { + const auto res = rfl::yaml::read(data); + if (!res) { + std::cout << res.error()->what() << std::endl; + } + } +} +BENCHMARK(BM_person_read_reflect_cpp_yaml); + +// ---------------------------------------------------------------------------- + +} // namespace person_read + diff --git a/benchmarks/all/person_write.cpp b/benchmarks/all/person_write.cpp new file mode 100644 index 00000000..d9405ce9 --- /dev/null +++ b/benchmarks/all/person_write.cpp @@ -0,0 +1,136 @@ +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace person_write { + +// ---------------------------------------------------------------------------- + +struct Person { + std::string first_name; + std::string last_name = "Simpson"; + int age; + std::string town = "Springfield"; + std::vector children; +}; + +// ---------------------------------------------------------------------------- + +static Person load_data() { + const auto bart = Person{.first_name = "Bart", .age = 10}; + + const auto lisa = Person{.first_name = "Lisa", .age = 8}; + + const auto maggie = Person{.first_name = "Maggie", .age = 0}; + + return Person{.first_name = "Homer", + .age = 45, + .children = std::vector({bart, lisa, maggie})}; +} + +// ---------------------------------------------------------------------------- + +static void BM_person_write_reflect_cpp_bson(benchmark::State &state) { + const auto data = load_data(); + for (auto _ : state) { + const auto output = rfl::bson::write(data); + if (output.size() == 0) { + std::cout << "No output" << std::endl; + } + } +} +BENCHMARK(BM_person_write_reflect_cpp_bson); + +static void BM_person_write_reflect_cpp_cbor(benchmark::State &state) { + const auto data = load_data(); + for (auto _ : state) { + const auto output = rfl::cbor::write(data); + if (output.size() == 0) { + std::cout << "No output" << std::endl; + } + } +} +BENCHMARK(BM_person_write_reflect_cpp_cbor); + +static void BM_person_write_reflect_cpp_flexbuf(benchmark::State &state) { + const auto data = load_data(); + for (auto _ : state) { + const auto output = rfl::flexbuf::write(data); + if (output.size() == 0) { + std::cout << "No output" << std::endl; + } + } +} +BENCHMARK(BM_person_write_reflect_cpp_flexbuf); + +static void BM_person_write_reflect_cpp_json(benchmark::State &state) { + const auto data = load_data(); + for (auto _ : state) { + const auto output = rfl::json::write(data); + if (output.size() == 0) { + std::cout << "No output" << std::endl; + } + } +} +BENCHMARK(BM_person_write_reflect_cpp_json); + +static void BM_person_write_reflect_cpp_msgpack(benchmark::State &state) { + const auto data = load_data(); + for (auto _ : state) { + const auto output = rfl::msgpack::write(data); + if (output.size() == 0) { + std::cout << "No output" << std::endl; + } + } +} +BENCHMARK(BM_person_write_reflect_cpp_msgpack); + +static void BM_person_write_reflect_cpp_toml(benchmark::State &state) { + const auto data = load_data(); + for (auto _ : state) { + const auto output = rfl::toml::write(data); + if (output.size() == 0) { + std::cout << "No output" << std::endl; + } + } +} +BENCHMARK(BM_person_write_reflect_cpp_toml); + +static void BM_person_write_reflect_cpp_xml(benchmark::State &state) { + const auto data = load_data(); + for (auto _ : state) { + const auto output = rfl::xml::write(data); + if (output.size() == 0) { + std::cout << "No output" << std::endl; + } + } +} +BENCHMARK(BM_person_write_reflect_cpp_xml); + +static void BM_person_write_reflect_cpp_yaml(benchmark::State &state) { + const auto data = load_data(); + for (auto _ : state) { + const auto output = rfl::yaml::write(data); + if (output.size() == 0) { + std::cout << "No output" << std::endl; + } + } +} +BENCHMARK(BM_person_write_reflect_cpp_yaml); + +// ---------------------------------------------------------------------------- + +} // namespace person_write + diff --git a/benchmarks/json/simple_read.cpp b/benchmarks/json/person.cpp similarity index 93% rename from benchmarks/json/simple_read.cpp rename to benchmarks/json/person.cpp index 18e5b057..6fde5ad1 100644 --- a/benchmarks/json/simple_read.cpp +++ b/benchmarks/json/person.cpp @@ -10,7 +10,7 @@ #include #include -namespace simple_read { +namespace person_read { // ---------------------------------------------------------------------------- @@ -240,7 +240,7 @@ static rfl::Result read_using_yyjson() { // ---------------------------------------------------------------------------- -static void BM_simple_read_nlohmann(benchmark::State &state) { +static void BM_person_read_nlohmann(benchmark::State &state) { for (auto _ : state) { const auto res = read_using_nlohmann(); if (!res) { @@ -248,9 +248,9 @@ static void BM_simple_read_nlohmann(benchmark::State &state) { } } } -BENCHMARK(BM_simple_read_nlohmann); +BENCHMARK(BM_person_read_nlohmann); -static void BM_simple_read_rapidjson(benchmark::State &state) { +static void BM_person_read_rapidjson(benchmark::State &state) { for (auto _ : state) { const auto res = read_using_rapidjson(); if (!res) { @@ -258,9 +258,9 @@ static void BM_simple_read_rapidjson(benchmark::State &state) { } } } -BENCHMARK(BM_simple_read_rapidjson); +BENCHMARK(BM_person_read_rapidjson); -static void BM_simple_read_simdjson(benchmark::State &state) { +static void BM_person_read_simdjson(benchmark::State &state) { for (auto _ : state) { const auto res = read_using_simdjson(); if (!res) { @@ -268,9 +268,9 @@ static void BM_simple_read_simdjson(benchmark::State &state) { } } } -BENCHMARK(BM_simple_read_simdjson); +BENCHMARK(BM_person_read_simdjson); -static void BM_simple_read_yyjson(benchmark::State &state) { +static void BM_person_read_yyjson(benchmark::State &state) { for (auto _ : state) { const auto res = read_using_yyjson(); if (!res) { @@ -278,9 +278,9 @@ static void BM_simple_read_yyjson(benchmark::State &state) { } } } -BENCHMARK(BM_simple_read_yyjson); +BENCHMARK(BM_person_read_yyjson); -static void BM_simple_read_reflect_cpp(benchmark::State &state) { +static void BM_person_read_reflect_cpp(benchmark::State &state) { for (auto _ : state) { const auto res = rfl::json::read(json_string); if (!res) { @@ -288,9 +288,9 @@ static void BM_simple_read_reflect_cpp(benchmark::State &state) { } } } -BENCHMARK(BM_simple_read_reflect_cpp); +BENCHMARK(BM_person_read_reflect_cpp); // ---------------------------------------------------------------------------- -} // namespace simple_read +} // namespace person_read