Added the licenses dataset as a benchmark (#113)

This commit is contained in:
liuzicheng1987
2024-06-05 22:24:36 +02:00
committed by GitHub
parent ab14d14af2
commit b757013638
10 changed files with 3312 additions and 1 deletions
+2
View File
@@ -45,3 +45,5 @@ jobs:
./build/benchmarks/json/reflect-cpp-json-benchmarks --benchmark_filter=simple_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
+2
View File
@@ -38,3 +38,5 @@ jobs:
./build/benchmarks/json/reflect-cpp-json-benchmarks --benchmark_filter=simple_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
+2
View File
@@ -40,3 +40,5 @@ jobs:
./build/benchmarks/json/reflect-cpp-json-benchmarks --benchmark_filter=simple_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
+2
View File
@@ -37,3 +37,5 @@ jobs:
./build/benchmarks/json/reflect-cpp-json-benchmarks --benchmark_filter=simple_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
+2
View File
@@ -33,3 +33,5 @@ jobs:
.\build\benchmarks\json\Release\reflect-cpp-json-benchmarks.exe --benchmark_filter=simple_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
+156
View File
@@ -0,0 +1,156 @@
#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 licenses_read {
// ----------------------------------------------------------------------------
struct Identifier {
std::string identifier;
std::string scheme;
};
struct Link {
std::string note;
std::string url;
};
struct OtherName {
std::string name;
std::optional<std::string> note;
};
struct Text {
std::string media_type;
std::string title;
std::string url;
};
struct License {
std::string id;
std::vector<Identifier> identifiers;
std::vector<Link> links;
std::string name;
std::vector<OtherName> other_names;
std::optional<std::string> superseded_by;
std::vector<std::string> keywords;
std::vector<Text> text;
};
struct Licenses {
std::vector<License> licenses;
};
// ----------------------------------------------------------------------------
static Licenses load_data() {
return rfl::json::load<Licenses>("benchmarks/data/licenses.json").value();
}
// ----------------------------------------------------------------------------
static void BM_licenses_read_reflect_cpp_bson(benchmark::State &state) {
const auto data = rfl::bson::write(load_data());
for (auto _ : state) {
const auto res = rfl::bson::read<Licenses>(data);
if (!res) {
std::cout << res.error()->what() << std::endl;
}
}
}
BENCHMARK(BM_licenses_read_reflect_cpp_bson);
static void BM_licenses_read_reflect_cpp_cbor(benchmark::State &state) {
const auto data = rfl::cbor::write(load_data());
for (auto _ : state) {
const auto res = rfl::cbor::read<Licenses>(data);
if (!res) {
std::cout << res.error()->what() << std::endl;
}
}
}
BENCHMARK(BM_licenses_read_reflect_cpp_cbor);
static void BM_licenses_read_reflect_cpp_flexbuf(benchmark::State &state) {
const auto data = rfl::flexbuf::write(load_data());
for (auto _ : state) {
const auto res = rfl::flexbuf::read<Licenses>(data);
if (!res) {
std::cout << res.error()->what() << std::endl;
}
}
}
BENCHMARK(BM_licenses_read_reflect_cpp_flexbuf);
static void BM_licenses_read_reflect_cpp_json(benchmark::State &state) {
const auto data = rfl::json::write(load_data());
for (auto _ : state) {
const auto res = rfl::json::read<Licenses>(data);
if (!res) {
std::cout << res.error()->what() << std::endl;
}
}
}
BENCHMARK(BM_licenses_read_reflect_cpp_json);
static void BM_licenses_read_reflect_cpp_msgpack(benchmark::State &state) {
const auto data = rfl::msgpack::write(load_data());
for (auto _ : state) {
const auto res = rfl::msgpack::read<Licenses>(data);
if (!res) {
std::cout << res.error()->what() << std::endl;
}
}
}
BENCHMARK(BM_licenses_read_reflect_cpp_msgpack);
static void BM_licenses_read_reflect_cpp_xml(benchmark::State &state) {
const auto data = rfl::xml::write<"license">(load_data());
for (auto _ : state) {
const auto res = rfl::xml::read<Licenses>(data);
if (!res) {
std::cout << res.error()->what() << std::endl;
}
}
}
BENCHMARK(BM_licenses_read_reflect_cpp_xml);
static void BM_licenses_read_reflect_cpp_toml(benchmark::State &state) {
const auto data = rfl::toml::write(load_data());
for (auto _ : state) {
const auto res = rfl::toml::read<Licenses>(data);
if (!res) {
std::cout << res.error()->what() << std::endl;
}
}
}
BENCHMARK(BM_licenses_read_reflect_cpp_toml);
static void BM_licenses_read_reflect_cpp_yaml(benchmark::State &state) {
const auto data = rfl::yaml::write(load_data());
for (auto _ : state) {
const auto res = rfl::yaml::read<Licenses>(data);
if (!res) {
std::cout << res.error()->what() << std::endl;
}
}
}
BENCHMARK(BM_licenses_read_reflect_cpp_yaml);
// ----------------------------------------------------------------------------
} // namespace licenses_read
+156
View File
@@ -0,0 +1,156 @@
#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 licenses_write {
// ----------------------------------------------------------------------------
struct Identifier {
std::string identifier;
std::string scheme;
};
struct Link {
std::string note;
std::string url;
};
struct OtherName {
std::string name;
std::optional<std::string> note;
};
struct Text {
std::string media_type;
std::string title;
std::string url;
};
struct License {
std::string id;
std::vector<Identifier> identifiers;
std::vector<Link> links;
std::string name;
std::vector<OtherName> other_names;
std::optional<std::string> superseded_by;
std::vector<std::string> keywords;
std::vector<Text> text;
};
struct Licenses {
std::vector<License> licenses;
};
// ----------------------------------------------------------------------------
static Licenses load_data() {
return rfl::json::load<Licenses>("benchmarks/data/licenses.json").value();
}
// ----------------------------------------------------------------------------
static void BM_licenses_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_licenses_write_reflect_cpp_bson);
static void BM_licenses_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_licenses_write_reflect_cpp_cbor);
static void BM_licenses_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_licenses_write_reflect_cpp_flexbuf);
static void BM_licenses_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_licenses_write_reflect_cpp_json);
static void BM_licenses_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_licenses_write_reflect_cpp_msgpack);
static void BM_licenses_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_licenses_write_reflect_cpp_toml);
static void BM_licenses_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_licenses_write_reflect_cpp_xml);
static void BM_licenses_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_licenses_write_reflect_cpp_yaml);
// ----------------------------------------------------------------------------
} // namespace licenses_write
File diff suppressed because it is too large Load Diff
+8
View File
@@ -143,7 +143,11 @@ struct Reader {
return err;
}
}
} else {
return Error("Could not init the array iteration.");
}
} else {
return Error("Could not init array.");
}
return std::nullopt;
}
@@ -160,7 +164,11 @@ struct Reader {
const char* k = bson_iter_key(&iter);
_object_reader.read(std::string_view(k), to_input_var(&iter));
}
} else {
return Error("Could not init the object iteration.");
}
} else {
return Error("Could not init object.");
}
return std::nullopt;
}
+1 -1
View File
@@ -238,7 +238,7 @@ struct Reader {
return err;
}
_buffer->resize(length + 1);
(*_buffer)[length] = '\0';
_buffer->back() = '\0';
return cbor_value_copy_text_string(_ptr, _buffer->data(), &length, NULL);
}
};