Skip to content

Commit 222c52a

Browse files
Fixed conflicts
2 parents 62cd4c7 + a0ab524 commit 222c52a

93 files changed

Lines changed: 3144 additions & 68 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/linux.yaml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,16 @@ jobs:
120120
echo '## Benchmarks across different formats' >> $GITHUB_STEP_SUMMARY
121121
echo '```' >> $GITHUB_STEP_SUMMARY
122122
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=canada_read >> $GITHUB_STEP_SUMMARY
123+
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=parser_inlining >> $GITHUB_STEP_SUMMARY
123124
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=canada_write >> $GITHUB_STEP_SUMMARY
125+
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=field_dispatch >> $GITHUB_STEP_SUMMARY
124126
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=licenses_read >> $GITHUB_STEP_SUMMARY
125127
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=licenses_write >> $GITHUB_STEP_SUMMARY
126128
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=person_read >> $GITHUB_STEP_SUMMARY
127129
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=person_write >> $GITHUB_STEP_SUMMARY
130+
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=vectors_read >> $GITHUB_STEP_SUMMARY
131+
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=points_read >> $GITHUB_STEP_SUMMARY
132+
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=bulk_numeric_vectors >> $GITHUB_STEP_SUMMARY
128133
echo '```' >> $GITHUB_STEP_SUMMARY
129134
echo '## Benchmarks for JSON' >> $GITHUB_STEP_SUMMARY
130135
echo '```' >> $GITHUB_STEP_SUMMARY

‎.github/workflows/macos.yaml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,16 @@ jobs:
6262
echo '## Benchmarks across different formats' >> $GITHUB_STEP_SUMMARY
6363
echo '```' >> $GITHUB_STEP_SUMMARY
6464
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=canada_read >> $GITHUB_STEP_SUMMARY
65+
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=parser_inlining >> $GITHUB_STEP_SUMMARY
6566
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=canada_write >> $GITHUB_STEP_SUMMARY
67+
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=field_dispatch >> $GITHUB_STEP_SUMMARY
6668
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=licenses_read >> $GITHUB_STEP_SUMMARY
6769
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=licenses_write >> $GITHUB_STEP_SUMMARY
6870
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=person_read >> $GITHUB_STEP_SUMMARY
6971
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=person_write >> $GITHUB_STEP_SUMMARY
72+
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=vectors_read >> $GITHUB_STEP_SUMMARY
73+
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=points_read >> $GITHUB_STEP_SUMMARY
74+
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=bulk_numeric_vectors >> $GITHUB_STEP_SUMMARY
7075
echo '```' >> $GITHUB_STEP_SUMMARY
7176
echo '## Benchmarks for JSON' >> $GITHUB_STEP_SUMMARY
7277
echo '```' >> $GITHUB_STEP_SUMMARY

‎.github/workflows/windows.yaml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,16 @@ jobs:
6161
echo '## Benchmarks across different formats' >> $GITHUB_STEP_SUMMARY
6262
echo '```' >> $GITHUB_STEP_SUMMARY
6363
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=canada_read >> $GITHUB_STEP_SUMMARY
64+
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=parser_inlining >> $GITHUB_STEP_SUMMARY
6465
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=canada_write >> $GITHUB_STEP_SUMMARY
66+
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=field_dispatch >> $GITHUB_STEP_SUMMARY
6567
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=licenses_read >> $GITHUB_STEP_SUMMARY
6668
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=licenses_write >> $GITHUB_STEP_SUMMARY
6769
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=person_read >> $GITHUB_STEP_SUMMARY
6870
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=person_write >> $GITHUB_STEP_SUMMARY
71+
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=vectors_read >> $GITHUB_STEP_SUMMARY
72+
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=points_read >> $GITHUB_STEP_SUMMARY
73+
./build/benchmarks/all/reflect-cpp-all-format-benchmarks --benchmark_filter=bulk_numeric_vectors >> $GITHUB_STEP_SUMMARY
6974
echo '```' >> $GITHUB_STEP_SUMMARY
7075
echo '## Benchmarks for JSON' >> $GITHUB_STEP_SUMMARY
7176
echo '```' >> $GITHUB_STEP_SUMMARY
Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
#include <benchmark/benchmark.h>
2+
3+
#include <cstddef>
4+
#include <cstdint>
5+
#include <rfl/boost_serialization.hpp>
6+
#include <rfl/cereal.hpp>
7+
#include <rfl/yas.hpp>
8+
#include <sstream>
9+
#include <string>
10+
#include <vector>
11+
12+
namespace bulk_numeric_vectors {
13+
14+
struct Point2 {
15+
double x;
16+
double y;
17+
18+
bool operator==(const Point2&) const = default;
19+
};
20+
21+
struct Camera {
22+
std::vector<Point2> keypoints;
23+
std::vector<std::uint64_t> landmark_ids;
24+
25+
bool operator==(const Camera&) const = default;
26+
};
27+
28+
struct World {
29+
std::vector<Camera> cameras;
30+
31+
bool operator==(const World&) const = default;
32+
};
33+
34+
static Point2 make_point(std::size_t index) {
35+
return {
36+
static_cast<double>(static_cast<std::int64_t>(index % 65536) - 32768) *
37+
0.125,
38+
static_cast<double>(static_cast<std::int64_t>((index * 17) % 65536) -
39+
32768) *
40+
0.25};
41+
}
42+
43+
static std::uint64_t make_id(std::size_t index) {
44+
return static_cast<std::uint64_t>(index) * UINT64_C(0x9e3779b97f4a7c15) +
45+
UINT64_C(0x123456789abcdef0);
46+
}
47+
48+
static std::vector<std::uint64_t> make_ids(std::size_t count) {
49+
std::vector<std::uint64_t> values(count);
50+
for (std::size_t i = 0; i < count; ++i) values[i] = make_id(i);
51+
return values;
52+
}
53+
54+
static std::vector<Point2> make_points(std::size_t count) {
55+
std::vector<Point2> values(count);
56+
for (std::size_t i = 0; i < count; ++i) values[i] = make_point(i);
57+
return values;
58+
}
59+
60+
static World make_world(std::size_t cameras, std::size_t points_per_camera) {
61+
World world;
62+
world.cameras.resize(cameras);
63+
for (std::size_t i = 0; i < cameras; ++i) {
64+
auto& camera = world.cameras[i];
65+
camera.keypoints.resize(points_per_camera);
66+
camera.landmark_ids.resize(points_per_camera);
67+
for (std::size_t j = 0; j < points_per_camera; ++j) {
68+
const auto index = i * points_per_camera + j;
69+
camera.keypoints[j] = make_point(index);
70+
camera.landmark_ids[j] = make_id(index);
71+
}
72+
}
73+
return world;
74+
}
75+
76+
enum class Format { cereal, yas, boost_serialization };
77+
78+
template <Format F, class T>
79+
void write(const T& input, std::ostream& stream) {
80+
if constexpr (F == Format::cereal)
81+
rfl::cereal::write(input, stream);
82+
else if constexpr (F == Format::yas)
83+
rfl::yas::write(input, stream);
84+
else
85+
rfl::boost_serialization::write(input, stream);
86+
}
87+
88+
template <Format F, class T>
89+
auto read(const std::string& bytes) {
90+
if constexpr (F == Format::yas) {
91+
return rfl::yas::read<T>(bytes);
92+
} else {
93+
std::istringstream stream(bytes);
94+
if constexpr (F == Format::cereal)
95+
return rfl::cereal::read<T>(stream);
96+
else
97+
return rfl::boost_serialization::read<T>(stream);
98+
}
99+
}
100+
101+
template <bool Read, Format F, class T>
102+
static void run(benchmark::State& state, const T& input, std::int64_t items) {
103+
std::ostringstream output;
104+
write<F>(input, output);
105+
const auto bytes = output.str();
106+
{
107+
const auto result = read<F, T>(bytes);
108+
if (!result) {
109+
state.SkipWithError(result.error().what());
110+
return;
111+
}
112+
if (*result != input) {
113+
state.SkipWithError("Binary round trip changed the input");
114+
return;
115+
}
116+
}
117+
118+
// Stream construction, serialization, and destruction are timed. Fixture
119+
// generation, output extraction, and equality checks are outside the loop.
120+
for (auto _ : state) {
121+
if constexpr (Read) {
122+
auto result = read<F, T>(bytes);
123+
if (!result) {
124+
state.SkipWithError(result.error().what());
125+
break;
126+
}
127+
benchmark::DoNotOptimize(result);
128+
} else {
129+
std::ostringstream stream;
130+
write<F>(input, stream);
131+
benchmark::DoNotOptimize(stream);
132+
}
133+
}
134+
state.SetItemsProcessed(state.iterations() * items);
135+
state.SetBytesProcessed(state.iterations() *
136+
static_cast<std::int64_t>(bytes.size()));
137+
state.counters["serialized_bytes"] = static_cast<double>(bytes.size());
138+
}
139+
140+
template <bool Read, Format F>
141+
static void BM_bulk_numeric_vectors_ids(benchmark::State& state) {
142+
const auto input = make_ids(static_cast<std::size_t>(state.range(0)));
143+
run<Read, F>(state, input, state.range(0));
144+
}
145+
146+
template <bool Read, Format F>
147+
static void BM_bulk_numeric_vectors_points(benchmark::State& state) {
148+
const auto input = make_points(static_cast<std::size_t>(state.range(0)));
149+
run<Read, F>(state, input, state.range(0));
150+
}
151+
152+
template <bool Read, Format F>
153+
static void BM_bulk_numeric_vectors_complete(benchmark::State& state) {
154+
const auto input = make_world(static_cast<std::size_t>(state.range(0)),
155+
static_cast<std::size_t>(state.range(1)));
156+
run<Read, F>(state, input, state.range(0) * state.range(1));
157+
}
158+
159+
BENCHMARK_TEMPLATE(BM_bulk_numeric_vectors_ids, false, Format::cereal)
160+
->Name("bulk_numeric_vectors/cereal/ids/write")
161+
->Arg(1500000)
162+
->Unit(benchmark::kMillisecond);
163+
BENCHMARK_TEMPLATE(BM_bulk_numeric_vectors_ids, true, Format::cereal)
164+
->Name("bulk_numeric_vectors/cereal/ids/read")
165+
->Arg(1500000)
166+
->Unit(benchmark::kMillisecond);
167+
BENCHMARK_TEMPLATE(BM_bulk_numeric_vectors_points, false, Format::cereal)
168+
->Name("bulk_numeric_vectors/cereal/points/write")
169+
->Arg(1500000)
170+
->Unit(benchmark::kMillisecond);
171+
BENCHMARK_TEMPLATE(BM_bulk_numeric_vectors_points, true, Format::cereal)
172+
->Name("bulk_numeric_vectors/cereal/points/read")
173+
->Arg(1500000)
174+
->Unit(benchmark::kMillisecond);
175+
BENCHMARK_TEMPLATE(BM_bulk_numeric_vectors_complete, false, Format::cereal)
176+
->Name("bulk_numeric_vectors/cereal/complete/write")
177+
->Args({500, 3000})
178+
->ArgNames({"cameras", "keypoints"})
179+
->Unit(benchmark::kMillisecond);
180+
BENCHMARK_TEMPLATE(BM_bulk_numeric_vectors_complete, true, Format::cereal)
181+
->Name("bulk_numeric_vectors/cereal/complete/read")
182+
->Args({500, 3000})
183+
->ArgNames({"cameras", "keypoints"})
184+
->Unit(benchmark::kMillisecond);
185+
BENCHMARK_TEMPLATE(BM_bulk_numeric_vectors_ids, false, Format::yas)
186+
->Name("bulk_numeric_vectors/yas/ids/write")
187+
->Arg(1500000)
188+
->Unit(benchmark::kMillisecond);
189+
BENCHMARK_TEMPLATE(BM_bulk_numeric_vectors_ids, true, Format::yas)
190+
->Name("bulk_numeric_vectors/yas/ids/read")
191+
->Arg(1500000)
192+
->Unit(benchmark::kMillisecond);
193+
BENCHMARK_TEMPLATE(BM_bulk_numeric_vectors_points, false, Format::yas)
194+
->Name("bulk_numeric_vectors/yas/points/write")
195+
->Arg(1500000)
196+
->Unit(benchmark::kMillisecond);
197+
BENCHMARK_TEMPLATE(BM_bulk_numeric_vectors_points, true, Format::yas)
198+
->Name("bulk_numeric_vectors/yas/points/read")
199+
->Arg(1500000)
200+
->Unit(benchmark::kMillisecond);
201+
BENCHMARK_TEMPLATE(BM_bulk_numeric_vectors_complete, false, Format::yas)
202+
->Name("bulk_numeric_vectors/yas/complete/write")
203+
->Args({500, 3000})
204+
->ArgNames({"cameras", "keypoints"})
205+
->Unit(benchmark::kMillisecond);
206+
BENCHMARK_TEMPLATE(BM_bulk_numeric_vectors_complete, true, Format::yas)
207+
->Name("bulk_numeric_vectors/yas/complete/read")
208+
->Args({500, 3000})
209+
->ArgNames({"cameras", "keypoints"})
210+
->Unit(benchmark::kMillisecond);
211+
BENCHMARK_TEMPLATE(BM_bulk_numeric_vectors_ids, false,
212+
Format::boost_serialization)
213+
->Name("bulk_numeric_vectors/boost_serialization/ids/write")
214+
->Arg(1500000)
215+
->Unit(benchmark::kMillisecond);
216+
BENCHMARK_TEMPLATE(BM_bulk_numeric_vectors_ids, true,
217+
Format::boost_serialization)
218+
->Name("bulk_numeric_vectors/boost_serialization/ids/read")
219+
->Arg(1500000)
220+
->Unit(benchmark::kMillisecond);
221+
BENCHMARK_TEMPLATE(BM_bulk_numeric_vectors_points, false,
222+
Format::boost_serialization)
223+
->Name("bulk_numeric_vectors/boost_serialization/points/write")
224+
->Arg(1500000)
225+
->Unit(benchmark::kMillisecond);
226+
BENCHMARK_TEMPLATE(BM_bulk_numeric_vectors_points, true,
227+
Format::boost_serialization)
228+
->Name("bulk_numeric_vectors/boost_serialization/points/read")
229+
->Arg(1500000)
230+
->Unit(benchmark::kMillisecond);
231+
BENCHMARK_TEMPLATE(BM_bulk_numeric_vectors_complete, false,
232+
Format::boost_serialization)
233+
->Name("bulk_numeric_vectors/boost_serialization/complete/write")
234+
->Args({500, 3000})
235+
->ArgNames({"cameras", "keypoints"})
236+
->Unit(benchmark::kMillisecond);
237+
BENCHMARK_TEMPLATE(BM_bulk_numeric_vectors_complete, true,
238+
Format::boost_serialization)
239+
->Name("bulk_numeric_vectors/boost_serialization/complete/read")
240+
->Args({500, 3000})
241+
->ArgNames({"cameras", "keypoints"})
242+
->Unit(benchmark::kMillisecond);
243+
244+
} // namespace bulk_numeric_vectors

‎benchmarks/all/field_dispatch.hpp‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#ifndef BENCHMARK_FIELD_DISPATCH_HPP_
2+
#define BENCHMARK_FIELD_DISPATCH_HPP_
3+
#include <benchmark/benchmark.h>
4+
5+
#include <cstdint>
6+
#include <vector>
7+
namespace field_dispatch {
8+
struct Record2 {
9+
float field0 = 0;
10+
float field1 = 1;
11+
bool operator==(const Record2&) const = default;
12+
};
13+
struct Record16 {
14+
float field0 = 0;
15+
float field1 = 1;
16+
float field2 = 2;
17+
float field3 = 3;
18+
float field4 = 4;
19+
float field5 = 5;
20+
float field6 = 6;
21+
float field7 = 7;
22+
float field8 = 8;
23+
float field9 = 9;
24+
float field10 = 10;
25+
float field11 = 11;
26+
float field12 = 12;
27+
float field13 = 13;
28+
float field14 = 14;
29+
float field15 = 15;
30+
bool operator==(const Record16&) const = default;
31+
};
32+
template <class Record>
33+
struct Data {
34+
std::vector<Record> records;
35+
bool operator==(const Data&) const = default;
36+
};
37+
template <class Record>
38+
auto make_data(std::size_t size) {
39+
Data<Record> data;
40+
data.records.resize(size);
41+
for (std::size_t i = 0; i < size; ++i) {
42+
data.records[i].field0 = static_cast<float>(i) * 0.5f;
43+
data.records[i].field1 = -static_cast<float>(i) * 0.25f;
44+
}
45+
return data;
46+
}
47+
template <class Record, class Write, class Read>
48+
void run(benchmark::State& state, Write write, Read read) {
49+
const auto input = make_data<Record>(state.range(0));
50+
const auto bytes = write(input);
51+
{
52+
const auto result = read(bytes);
53+
if (!result) {
54+
state.SkipWithError(result.error().what());
55+
return;
56+
}
57+
if (*result != input) {
58+
state.SkipWithError("Fields changed during round trip");
59+
return;
60+
}
61+
}
62+
for (auto _ : state) {
63+
auto result = read(bytes);
64+
if (!result) {
65+
state.SkipWithError(result.error().what());
66+
break;
67+
}
68+
benchmark::DoNotOptimize(result);
69+
}
70+
state.SetItemsProcessed(state.iterations() * state.range(0));
71+
state.SetBytesProcessed(state.iterations() *
72+
static_cast<std::int64_t>(bytes.size()));
73+
state.counters["serialized_bytes"] = static_cast<double>(bytes.size());
74+
}
75+
} // namespace field_dispatch
76+
#endif
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <rfl/avro.hpp>
2+
3+
#include "field_dispatch.hpp"
4+
namespace field_dispatch {
5+
template <class Record>
6+
void BM_field_dispatch_avro(benchmark::State& state) {
7+
const auto schema = rfl::avro::to_schema<Data<Record>>();
8+
run<Record>(
9+
state, [&](const auto& input) { return rfl::avro::write(input, schema); },
10+
[&](const auto& bytes) {
11+
return rfl::avro::read<Data<Record>>(bytes, schema);
12+
});
13+
}
14+
BENCHMARK_TEMPLATE(BM_field_dispatch_avro, Record2)
15+
->Arg(100000)
16+
->Unit(benchmark::kMillisecond);
17+
BENCHMARK_TEMPLATE(BM_field_dispatch_avro, Record16)
18+
->Arg(100000)
19+
->Unit(benchmark::kMillisecond);
20+
} // namespace field_dispatch

0 commit comments

Comments
 (0)