Skip to content

Commit 92f28cd

Browse files
Add yas to the benchmarks
1 parent 9881c88 commit 92f28cd

File tree

7 files changed

+73
-1
lines changed

7 files changed

+73
-1
lines changed

benchmarks/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ In summary, it is fair to say that reflect-cpp is among the fastest JSON librari
5050

5151
### How the different formats supported by reflect-cpp compare to each other
5252

53-
- flexbuffers and msgpack are the fastest two formats supported by reflect-cpp. They are particularly fast on datasets with a lot of numerical data, such as *canada*. flexbuffers is usually the fastest at reading data and msgpack is the fastest at writing.
53+
- flexbuffers, msgpack and yas are the fastest three formats supported by reflect-cpp. They are particularly fast on datasets with a lot of numerical data, such as *canada*. flexbuffers is usually the fastest at reading data and msgpack is the fastest at writing.
5454
- JSON is surprisingly fast. This is because reflect-cpp's JSON parser is built on top of yyjson, arguably the fastest JSON library for C or C++.
5555
- The performance of CBOR is disappointing. We have tried swapping out the underlying library, TinyCBOR, for libcbor, but the results are similar.
5656
- TOML and YAML are very slow when compared to the other formats. To be fair, these formats emphasize readability rather than speed.

benchmarks/all/canada_read.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <rfl/toml.hpp>
1313
#include <rfl/ubjson.hpp>
1414
#include <rfl/yaml.hpp>
15+
#include <rfl/yas.hpp>
1516
#include <vector>
1617

1718
namespace canada_read {
@@ -247,6 +248,17 @@ static void BM_canada_read_reflect_cpp_yaml(benchmark::State &state) {
247248
}
248249
BENCHMARK(BM_canada_read_reflect_cpp_yaml);
249250

251+
static void BM_canada_read_reflect_cpp_yas(benchmark::State &state) {
252+
const auto data = rfl::yas::write(load_data());
253+
for (auto _ : state) {
254+
const auto res = rfl::yas::read<FeatureCollection>(data);
255+
if (!res) {
256+
std::cout << res.error().what() << std::endl;
257+
}
258+
}
259+
}
260+
BENCHMARK(BM_canada_read_reflect_cpp_yas);
261+
250262
// ----------------------------------------------------------------------------
251263

252264
} // namespace canada_read

benchmarks/all/canada_write.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <rfl/toml.hpp>
1313
#include <rfl/ubjson.hpp>
1414
#include <rfl/yaml.hpp>
15+
#include <rfl/yas.hpp>
1516
#include <vector>
1617

1718
namespace canada_write {
@@ -231,6 +232,17 @@ static void BM_canada_write_reflect_cpp_yaml(benchmark::State &state) {
231232
}
232233
BENCHMARK(BM_canada_write_reflect_cpp_yaml);
233234

235+
static void BM_canada_write_reflect_cpp_yas(benchmark::State &state) {
236+
const auto data = load_data();
237+
for (auto _ : state) {
238+
const auto output = rfl::yas::write(data);
239+
if (output.size() == 0) {
240+
std::cout << "No output" << std::endl;
241+
}
242+
}
243+
}
244+
BENCHMARK(BM_canada_write_reflect_cpp_yas);
245+
234246
// ----------------------------------------------------------------------------
235247

236248
} // namespace canada_write

benchmarks/all/licenses_read.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <rfl/ubjson.hpp>
1515
#include <rfl/xml.hpp>
1616
#include <rfl/yaml.hpp>
17+
#include <rfl/yas.hpp>
1718
#include <vector>
1819

1920
namespace licenses_read {
@@ -270,6 +271,17 @@ static void BM_licenses_read_reflect_cpp_yaml(benchmark::State &state) {
270271
}
271272
BENCHMARK(BM_licenses_read_reflect_cpp_yaml);
272273

274+
static void BM_licenses_read_reflect_cpp_yas(benchmark::State &state) {
275+
const auto data = rfl::yas::write(load_data());
276+
for (auto _ : state) {
277+
const auto res = rfl::yas::read<Licenses>(data);
278+
if (!res) {
279+
std::cout << res.error().what() << std::endl;
280+
}
281+
}
282+
}
283+
BENCHMARK(BM_licenses_read_reflect_cpp_yas);
284+
273285
// ----------------------------------------------------------------------------
274286

275287
} // namespace licenses_read

benchmarks/all/licenses_write.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <rfl/ubjson.hpp>
1515
#include <rfl/xml.hpp>
1616
#include <rfl/yaml.hpp>
17+
#include <rfl/yas.hpp>
1718
#include <vector>
1819

1920
namespace licenses_write {
@@ -270,6 +271,17 @@ static void BM_licenses_write_reflect_cpp_yaml(benchmark::State &state) {
270271
}
271272
BENCHMARK(BM_licenses_write_reflect_cpp_yaml);
272273

274+
static void BM_licenses_write_reflect_cpp_yas(benchmark::State &state) {
275+
const auto data = load_data();
276+
for (auto _ : state) {
277+
const auto output = rfl::yas::write(data);
278+
if (output.size() == 0) {
279+
std::cout << "No output" << std::endl;
280+
}
281+
}
282+
}
283+
BENCHMARK(BM_licenses_write_reflect_cpp_yas);
284+
273285
// ----------------------------------------------------------------------------
274286

275287
} // namespace licenses_write

benchmarks/all/person_read.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <rfl/ubjson.hpp>
1414
#include <rfl/xml.hpp>
1515
#include <rfl/yaml.hpp>
16+
#include <rfl/yas.hpp>
1617
#include <vector>
1718
namespace person_read {
1819

@@ -248,6 +249,17 @@ static void BM_person_read_reflect_cpp_yaml(benchmark::State &state) {
248249
}
249250
BENCHMARK(BM_person_read_reflect_cpp_yaml);
250251

252+
static void BM_person_read_reflect_cpp_yas(benchmark::State &state) {
253+
const auto data = rfl::yas::write(load_data());
254+
for (auto _ : state) {
255+
const auto res = rfl::yas::read<Person>(data);
256+
if (!res) {
257+
std::cout << res.error().what() << std::endl;
258+
}
259+
}
260+
}
261+
BENCHMARK(BM_person_read_reflect_cpp_yas);
262+
251263
// ----------------------------------------------------------------------------
252264

253265
} // namespace person_read

benchmarks/all/person_write.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <rfl/ubjson.hpp>
1414
#include <rfl/xml.hpp>
1515
#include <rfl/yaml.hpp>
16+
#include <rfl/yas.hpp>
1617
#include <vector>
1718

1819
namespace person_write {
@@ -249,6 +250,17 @@ static void BM_person_write_reflect_cpp_yaml(benchmark::State &state) {
249250
}
250251
BENCHMARK(BM_person_write_reflect_cpp_yaml);
251252

253+
static void BM_person_write_reflect_cpp_yas(benchmark::State &state) {
254+
const auto data = load_data();
255+
for (auto _ : state) {
256+
const auto output = rfl::yas::write(data);
257+
if (output.size() == 0) {
258+
std::cout << "No output" << std::endl;
259+
}
260+
}
261+
}
262+
BENCHMARK(BM_person_write_reflect_cpp_yas);
263+
252264
// ----------------------------------------------------------------------------
253265

254266
} // namespace person_write

0 commit comments

Comments
 (0)