Skip to content

Commit dfc510f

Browse files
committed
Add bench_ondemand_largerandom to check theory about executable format
1 parent e7e09e4 commit dfc510f

File tree

7 files changed

+28
-115
lines changed

7 files changed

+28
-115
lines changed

benchmark/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
include_directories( . linux )
22
link_libraries(simdjson-windows-headers test-data)
33

4-
4+
# bench_sax links against the source
55
if (TARGET benchmark::benchmark)
66
add_executable(bench_sax bench_sax.cpp)
77
target_link_libraries(bench_sax PRIVATE simdjson-internal-flags simdjson-include-source benchmark::benchmark)
88
endif (TARGET benchmark::benchmark)
99

10+
# Everything else links against simdjson proper
1011
link_libraries(simdjson simdjson-flags)
12+
1113
add_executable(benchfeatures benchfeatures.cpp)
1214
add_executable(get_corpus_benchmark get_corpus_benchmark.cpp)
1315
add_executable(perfdiff perfdiff.cpp)
@@ -42,6 +44,7 @@ endif()
4244

4345
if (TARGET benchmark::benchmark)
4446
link_libraries(benchmark::benchmark)
47+
add_subdirectory(largerandom)
4548
add_executable(bench_parse_call bench_parse_call.cpp)
4649
add_executable(bench_dom_api bench_dom_api.cpp)
4750
add_executable(bench_ondemand bench_ondemand.cpp)

benchmark/largerandom/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
if (TARGET benchmark::benchmark)
2+
link_libraries(benchmark::benchmark)
3+
add_executable(bench_ondemand_largerandom bench_ondemand_largerandom.cpp)
4+
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.h"
13+
14+
BENCHMARK_MAIN();

benchmark/largerandom/dom.h

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -32,38 +32,6 @@ simdjson_really_inline bool Dom::Run(const padded_string &json) {
3232

3333
BENCHMARK_TEMPLATE(LargeRandom, Dom);
3434

35-
namespace sum {
36-
37-
class Dom {
38-
public:
39-
simdjson_really_inline bool Run(const padded_string &json);
40-
41-
simdjson_really_inline my_point &Result() { return sum; }
42-
simdjson_really_inline size_t ItemCount() { return count; }
43-
44-
private:
45-
dom::parser parser{};
46-
my_point sum{};
47-
size_t count{};
48-
};
49-
50-
simdjson_really_inline bool Dom::Run(const padded_string &json) {
51-
sum = { 0, 0, 0 };
52-
count = 0;
53-
54-
for (auto coord : parser.parse(json)) {
55-
sum.x += double(coord["x"]);
56-
sum.y += double(coord["y"]);
57-
sum.z += double(coord["z"]);
58-
count++;
59-
}
60-
61-
return true;
62-
}
63-
64-
BENCHMARK_TEMPLATE(LargeRandomSum, Dom);
65-
66-
} // namespace sum
6735
} // namespace largerandom
6836

6937
#endif // SIMDJSON_EXCEPTIONS

benchmark/largerandom/iter.h

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -48,45 +48,6 @@ simdjson_really_inline bool Iter::Run(const padded_string &json) {
4848

4949
BENCHMARK_TEMPLATE(LargeRandom, Iter);
5050

51-
52-
namespace sum {
53-
54-
class Iter {
55-
public:
56-
simdjson_really_inline bool Run(const padded_string &json);
57-
58-
simdjson_really_inline my_point &Result() { return sum; }
59-
simdjson_really_inline size_t ItemCount() { return count; }
60-
61-
private:
62-
ondemand::parser parser{};
63-
my_point sum{};
64-
size_t count{};
65-
};
66-
67-
simdjson_really_inline bool Iter::Run(const padded_string &json) {
68-
sum = {0,0,0};
69-
count = 0;
70-
71-
auto iter = parser.iterate_raw(json).value();
72-
if (!iter.start_array()) { return false; }
73-
do {
74-
if (!iter.start_object() || iter.field_key().value() != "x" || iter.field_value()) { return false; }
75-
sum.x += iter.consume_double();
76-
if (!iter.has_next_field() || iter.field_key().value() != "y" || iter.field_value()) { return false; }
77-
sum.y += iter.consume_double();
78-
if (!iter.has_next_field() || iter.field_key().value() != "z" || iter.field_value()) { return false; }
79-
sum.z += iter.consume_double();
80-
if (*iter.advance() != '}') { return false; }
81-
count++;
82-
} while (iter.has_next_element());
83-
84-
return true;
85-
}
86-
87-
BENCHMARK_TEMPLATE(LargeRandomSum, Iter);
88-
89-
} // namespace sum
9051
} // namespace largerandom
9152

9253
#endif // SIMDJSON_EXCEPTIONS

benchmark/largerandom/largerandom.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88

99
namespace largerandom {
1010
template<typename T> static void LargeRandom(benchmark::State &state);
11-
namespace sum {
12-
template<typename T> static void LargeRandomSum(benchmark::State &state);
13-
}
1411

1512
using namespace simdjson;
1613

@@ -59,22 +56,21 @@ simdjson_unused static std::ostream &operator<<(std::ostream &o, const my_point
5956
//
6057
#include <vector>
6158
#include "event_counter.h"
59+
#ifndef BENCHMARK_NO_DOM
6260
#include "dom.h"
61+
#endif
6362
#include "json_benchmark.h"
6463

6564
namespace largerandom {
6665

6766
template<typename T> static void LargeRandom(benchmark::State &state) {
67+
#ifdef BENCHMARK_NO_DOM
68+
JsonBenchmark<T, T>(state, get_built_json_array());
69+
#else
6870
JsonBenchmark<T, Dom>(state, get_built_json_array());
71+
#endif
6972
}
7073

71-
namespace sum {
72-
73-
template<typename T> static void LargeRandomSum(benchmark::State &state) {
74-
JsonBenchmark<T, Dom>(state, get_built_json_array());
75-
}
76-
77-
}
7874
} // namespace largerandom
7975

8076
#endif // SIMDJSON_EXCEPTIONS

benchmark/largerandom/ondemand.h

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,39 +33,6 @@ simdjson_really_inline bool OnDemand::Run(const padded_string &json) {
3333

3434
BENCHMARK_TEMPLATE(LargeRandom, OnDemand);
3535

36-
37-
namespace sum {
38-
39-
class OnDemand {
40-
public:
41-
simdjson_really_inline bool Run(const padded_string &json);
42-
simdjson_really_inline my_point &Result() { return sum; }
43-
simdjson_really_inline size_t ItemCount() { return count; }
44-
45-
private:
46-
ondemand::parser parser{};
47-
my_point sum{};
48-
size_t count{};
49-
};
50-
51-
simdjson_really_inline bool OnDemand::Run(const padded_string &json) {
52-
sum = {0,0,0};
53-
count = 0;
54-
55-
auto doc = parser.iterate(json);
56-
for (ondemand::object coord : doc.get_array()) {
57-
sum.x += double(coord.find_field("x"));
58-
sum.y += double(coord.find_field("y"));
59-
sum.z += double(coord.find_field("z"));
60-
count++;
61-
}
62-
63-
return true;
64-
}
65-
66-
BENCHMARK_TEMPLATE(LargeRandomSum, OnDemand);
67-
68-
} // namespace sum
6936
} // namespace largerandom
7037

7138
#endif // SIMDJSON_EXCEPTIONS

0 commit comments

Comments
 (0)