Skip to content

Commit 98666e8

Browse files
committed
Add unordered version of LargeRandom ondemand benchmark
1 parent d91491b commit 98666e8

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

benchmark/bench_ondemand.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ SIMDJSON_POP_DISABLE_WARNINGS
1212
#include "partial_tweets/dom.h"
1313

1414
#include "largerandom/ondemand.h"
15+
#include "largerandom/ondemand_unordered.h"
1516
// #include "largerandom/iter.h"
1617
#include "largerandom/dom.h"
1718

benchmark/largerandom/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
if (TARGET benchmark::benchmark)
22
link_libraries(benchmark::benchmark)
33
add_executable(bench_ondemand_largerandom bench_ondemand_largerandom.cpp)
4+
add_executable(bench_ondemand_unordered_largerandom bench_ondemand_unordered_largerandom.cpp)
45
endif()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "simdjson.h"
2+
#include <iostream>
3+
#include <sstream>
4+
#include <random>
5+
#include <vector>
6+
SIMDJSON_PUSH_DISABLE_ALL_WARNINGS
7+
#include <benchmark/benchmark.h>
8+
SIMDJSON_POP_DISABLE_WARNINGS
9+
10+
#define BENCHMARK_NO_DOM
11+
12+
#include "largerandom/ondemand_unordered.h"
13+
14+
BENCHMARK_MAIN();
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#pragma once
2+
3+
#if SIMDJSON_EXCEPTIONS
4+
5+
#include "largerandom.h"
6+
7+
namespace largerandom {
8+
9+
using namespace simdjson;
10+
using namespace simdjson::builtin;
11+
12+
class OnDemandUnordered {
13+
public:
14+
simdjson_really_inline bool Run(const padded_string &json);
15+
simdjson_really_inline const std::vector<my_point> &Result() { return container; }
16+
simdjson_really_inline size_t ItemCount() { return container.size(); }
17+
18+
private:
19+
ondemand::parser parser{};
20+
std::vector<my_point> container{};
21+
};
22+
23+
simdjson_really_inline bool OnDemandUnordered::Run(const padded_string &json) {
24+
container.clear();
25+
26+
auto doc = parser.iterate(json);
27+
for (ondemand::object coord : doc) {
28+
container.emplace_back(my_point{coord["x"], coord["y"], coord["z"]});
29+
}
30+
31+
return true;
32+
}
33+
34+
BENCHMARK_TEMPLATE(LargeRandom, OnDemandUnordered);
35+
36+
} // namespace largerandom
37+
38+
#endif // SIMDJSON_EXCEPTIONS

0 commit comments

Comments
 (0)