File tree 4 files changed +122
-2
lines changed 4 files changed +122
-2
lines changed Original file line number Diff line number Diff line change @@ -23,8 +23,7 @@ class Dom {
23
23
simdjson_really_inline bool Dom::Run (const padded_string &json) {
24
24
container.clear ();
25
25
26
- dom::element doc = parser.parse (json);
27
- for (auto point : doc) {
26
+ for (auto point : parser.parse (json)) {
28
27
container.emplace_back (my_point{point[" x" ], point[" y" ], point[" z" ]});
29
28
}
30
29
@@ -33,6 +32,38 @@ simdjson_really_inline bool Dom::Run(const padded_string &json) {
33
32
34
33
BENCHMARK_TEMPLATE (LargeRandom, Dom);
35
34
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
36
67
} // namespace largerandom
37
68
38
69
#endif // SIMDJSON_EXCEPTIONS
Original file line number Diff line number Diff line change @@ -51,7 +51,48 @@ simdjson_really_inline bool Iter::Run(const padded_string &json) {
51
51
52
52
BENCHMARK_TEMPLATE (LargeRandom, Iter);
53
53
54
+ } // unnamed namespace
55
+
56
+ namespace sum {
57
+ namespace {
58
+
59
+ class Iter {
60
+ public:
61
+ simdjson_really_inline bool Run (const padded_string &json);
62
+
63
+ simdjson_really_inline my_point &Result () { return sum; }
64
+ simdjson_really_inline size_t ItemCount () { return count; }
65
+
66
+ private:
67
+ ondemand::parser parser{};
68
+ my_point sum{};
69
+ size_t count{};
70
+ };
71
+
72
+ simdjson_really_inline bool Iter::Run (const padded_string &json) {
73
+ sum = {0 ,0 ,0 };
74
+ count = 0 ;
75
+
76
+ auto iter = parser.iterate_raw (json).value ();
77
+ if (!iter.start_array ()) { return false ; }
78
+ do {
79
+ if (!iter.start_object () || !iter.find_field_raw (" x" )) { return false ; }
80
+ sum.x += iter.get_double ();
81
+ if (!iter.has_next_field () || !iter.find_field_raw (" y" )) { return false ; }
82
+ sum.y += iter.get_double ();
83
+ if (!iter.has_next_field () || !iter.find_field_raw (" z" )) { return false ; }
84
+ sum.z += iter.get_double ();
85
+ if (iter.skip_container ()) { return false ; } // Skip the rest of the tweet object
86
+ count++;
87
+ } while (iter.has_next_element ());
88
+
89
+ return true ;
54
90
}
91
+
92
+ BENCHMARK_TEMPLATE (LargeRandomSum, Iter);
93
+
94
+ } // unnamed namespace
95
+ } // namespace sum
55
96
} // namespace largerandom
56
97
57
98
#endif // SIMDJSON_EXCEPTIONS
Original file line number Diff line number Diff line change 8
8
9
9
namespace largerandom {
10
10
template <typename T> static void LargeRandom (benchmark::State &state);
11
+ namespace sum {
12
+ template <typename T> static void LargeRandomSum (benchmark::State &state);
13
+ }
11
14
12
15
using namespace simdjson ;
13
16
@@ -65,6 +68,13 @@ template<typename T> static void LargeRandom(benchmark::State &state) {
65
68
JsonBenchmark<T, Dom>(state, get_built_json_array ());
66
69
}
67
70
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
+ }
68
78
} // namespace largerandom
69
79
70
80
#endif // SIMDJSON_EXCEPTIONS
Original file line number Diff line number Diff line change @@ -39,7 +39,45 @@ simdjson_really_inline bool OnDemand::Run(const padded_string &json) {
39
39
40
40
BENCHMARK_TEMPLATE (LargeRandom, OnDemand);
41
41
42
+ } // unnamed namespace
43
+
44
+ namespace sum {
45
+ namespace {
46
+
47
+ class OnDemand {
48
+ public:
49
+ simdjson_really_inline bool Run (const padded_string &json);
50
+
51
+ simdjson_really_inline my_point &Result () { return sum; }
52
+ simdjson_really_inline size_t ItemCount () { return count; }
53
+
54
+ private:
55
+ ondemand::parser parser{};
56
+ my_point sum{};
57
+ size_t count{};
58
+ };
59
+
60
+ simdjson_really_inline bool OnDemand::Run (const padded_string &json) {
61
+ sum = {0 ,0 ,0 };
62
+ count = 0 ;
63
+
64
+ auto doc = parser.iterate(json);
65
+ // TODO this sucks, you should be able to just say for ( ... : doc)
66
+ auto array = doc.get_array ();
67
+ for (ondemand::object coord : array) {
68
+ sum.x += double (coord[" x" ]);
69
+ sum.y += double (coord[" y" ]);
70
+ sum.z += double (coord[" z" ]);
71
+ count++;
72
+ }
73
+
74
+ return true ;
42
75
}
76
+
77
+ BENCHMARK_TEMPLATE (LargeRandomSum, OnDemand);
78
+
79
+ } // unnamed namespace
80
+ } // namespace sum
43
81
} // namespace largerandom
44
82
45
83
#endif // SIMDJSON_EXCEPTIONS
You can’t perform that action at this time.
0 commit comments