-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added benchmark across different formats
- Loading branch information
1 parent
601d984
commit 17441a5
Showing
7 changed files
with
160 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
project(reflect-cpp-all-format-benchmarks) | ||
|
||
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*.cpp") | ||
|
||
add_executable( | ||
reflect-cpp-all-format-benchmarks | ||
${SOURCES} | ||
) | ||
|
||
target_include_directories(reflect-cpp-all-format-benchmarks SYSTEM PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include") | ||
target_include_directories(reflect-cpp-all-format-benchmarks SYSTEM PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include/tinycbor") | ||
|
||
target_link_libraries( | ||
reflect-cpp-all-format-benchmarks | ||
PRIVATE | ||
reflectcpp | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
#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/yaml.hpp> | ||
#include <type_traits> | ||
#include <vector> | ||
|
||
namespace canada { | ||
|
||
// ---------------------------------------------------------------------------- | ||
|
||
struct Property { | ||
std::string name; | ||
}; | ||
|
||
struct Geometry { | ||
rfl::Literal<"Polygon"> type; | ||
std::vector<std::vector<std::tuple<double, double>>> coordinates; | ||
}; | ||
|
||
struct Feature { | ||
rfl::Literal<"Feature"> type; | ||
Property properties; | ||
Geometry geometry; | ||
}; | ||
|
||
struct FeatureCollection { | ||
rfl::Literal<"FeatureCollection"> type; | ||
std::vector<Feature> features; | ||
}; | ||
|
||
// ---------------------------------------------------------------------------- | ||
|
||
static FeatureCollection load_data() { | ||
return rfl::json::load<FeatureCollection>("benchmarks/json/data/canada.json") | ||
.value(); | ||
} | ||
|
||
// ---------------------------------------------------------------------------- | ||
|
||
static void BM_canada_read_reflect_cpp_bson(benchmark::State &state) { | ||
const auto data = rfl::bson::write(load_data()); | ||
for (auto _ : state) { | ||
const auto res = rfl::bson::read<FeatureCollection>(data); | ||
if (!res) { | ||
std::cout << res.error()->what() << std::endl; | ||
} | ||
} | ||
} | ||
BENCHMARK(BM_canada_read_reflect_cpp_bson); | ||
|
||
static void BM_canada_read_reflect_cpp_cbor(benchmark::State &state) { | ||
const auto data = rfl::cbor::write(load_data()); | ||
for (auto _ : state) { | ||
const auto res = rfl::cbor::read<FeatureCollection>(data); | ||
if (!res) { | ||
std::cout << res.error()->what() << std::endl; | ||
} | ||
} | ||
} | ||
BENCHMARK(BM_canada_read_reflect_cpp_cbor); | ||
|
||
static void BM_canada_read_reflect_cpp_flexbuf(benchmark::State &state) { | ||
const auto data = rfl::flexbuf::write(load_data()); | ||
for (auto _ : state) { | ||
const auto res = rfl::flexbuf::read<FeatureCollection>(data); | ||
if (!res) { | ||
std::cout << res.error()->what() << std::endl; | ||
} | ||
} | ||
} | ||
BENCHMARK(BM_canada_read_reflect_cpp_flexbuf); | ||
|
||
static void BM_canada_read_reflect_cpp_json(benchmark::State &state) { | ||
const auto data = rfl::json::write(load_data()); | ||
for (auto _ : state) { | ||
const auto res = rfl::json::read<FeatureCollection>(data); | ||
if (!res) { | ||
std::cout << res.error()->what() << std::endl; | ||
} | ||
} | ||
} | ||
BENCHMARK(BM_canada_read_reflect_cpp_json); | ||
|
||
static void BM_canada_read_reflect_cpp_msgpack(benchmark::State &state) { | ||
const auto data = rfl::msgpack::write(load_data()); | ||
for (auto _ : state) { | ||
const auto res = rfl::msgpack::read<FeatureCollection>(data); | ||
if (!res) { | ||
std::cout << res.error()->what() << std::endl; | ||
} | ||
} | ||
} | ||
BENCHMARK(BM_canada_read_reflect_cpp_msgpack); | ||
|
||
static void BM_canada_read_reflect_cpp_toml(benchmark::State &state) { | ||
const auto data = rfl::toml::write(load_data()); | ||
for (auto _ : state) { | ||
const auto res = rfl::toml::read<FeatureCollection>(data); | ||
if (!res) { | ||
std::cout << res.error()->what() << std::endl; | ||
} | ||
} | ||
} | ||
BENCHMARK(BM_canada_read_reflect_cpp_toml); | ||
|
||
static void BM_canada_read_reflect_cpp_yaml(benchmark::State &state) { | ||
const auto data = rfl::yaml::write(load_data()); | ||
for (auto _ : state) { | ||
const auto res = rfl::yaml::read<FeatureCollection>(data); | ||
if (!res) { | ||
std::cout << res.error()->what() << std::endl; | ||
} | ||
} | ||
} | ||
BENCHMARK(BM_canada_read_reflect_cpp_yaml); | ||
|
||
// ---------------------------------------------------------------------------- | ||
|
||
} // namespace canada | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#include <benchmark/benchmark.h> | ||
|
||
BENCHMARK_MAIN(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#include <benchmark/benchmark.h> | ||
|
||
BENCHMARK_MAIN(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -300,4 +300,3 @@ BENCHMARK(BM_simple_read_reflect_cpp); | |
|
||
} // namespace simple_read | ||
|
||
BENCHMARK_MAIN(); |