Added all format benchmarks for the person dataset (#114)

This commit is contained in:
liuzicheng1987
2024-06-06 20:44:22 +02:00
committed by GitHub
parent b757013638
commit 3039212b50
8 changed files with 299 additions and 17 deletions
+3 -1
View File
@@ -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
+3 -1
View File
@@ -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
+3 -1
View File
@@ -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
+3 -1
View File
@@ -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
+3 -1
View File
@@ -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
+136
View File
@@ -0,0 +1,136 @@
#include <benchmark/benchmark.h>
#include <array>
#include <iostream>
#include <optional>
#include <rfl/bson.hpp>
#include <rfl/cbor.hpp>
#include <rfl/flexbuf.hpp>
#include <rfl/json.hpp>
#include <rfl/msgpack.hpp>
#include <rfl/toml.hpp>
#include <rfl/xml.hpp>
#include <rfl/yaml.hpp>
#include <type_traits>
#include <vector>
namespace person_read {
// ----------------------------------------------------------------------------
struct Person {
std::string first_name;
std::string last_name = "Simpson";
int age;
std::string town = "Springfield";
std::vector<Person> 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<Person>({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<Person>(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<Person>(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<Person>(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<Person>(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<Person>(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<Person>(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<Person>(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<Person>(data);
if (!res) {
std::cout << res.error()->what() << std::endl;
}
}
}
BENCHMARK(BM_person_read_reflect_cpp_yaml);
// ----------------------------------------------------------------------------
} // namespace person_read
+136
View File
@@ -0,0 +1,136 @@
#include <benchmark/benchmark.h>
#include <array>
#include <iostream>
#include <optional>
#include <rfl/bson.hpp>
#include <rfl/cbor.hpp>
#include <rfl/flexbuf.hpp>
#include <rfl/json.hpp>
#include <rfl/msgpack.hpp>
#include <rfl/toml.hpp>
#include <rfl/xml.hpp>
#include <rfl/yaml.hpp>
#include <type_traits>
#include <vector>
namespace person_write {
// ----------------------------------------------------------------------------
struct Person {
std::string first_name;
std::string last_name = "Simpson";
int age;
std::string town = "Springfield";
std::vector<Person> 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<Person>({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
@@ -10,7 +10,7 @@
#include <type_traits>
#include <vector>
namespace simple_read {
namespace person_read {
// ----------------------------------------------------------------------------
@@ -240,7 +240,7 @@ static rfl::Result<Person> 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<Person>(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