Skip to content

Commit 6bb6e75

Browse files
committed
Fix points SAX to actually record points
1 parent 90a6c1f commit 6bb6e75

File tree

1 file changed

+51
-45
lines changed

1 file changed

+51
-45
lines changed

benchmark/bench_sax.cpp

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,16 @@ static void ondemand_tweets(State &state) {
8080
tweet_count += tweets.size();
8181
}
8282
// Gigabyte: https://en.wikipedia.org/wiki/Gigabyte
83-
state.counters["Gigabytes"] = benchmark::Counter(
83+
state.counters["bytes"] = benchmark::Counter(
8484
double(byte_count), benchmark::Counter::kIsRate,
8585
benchmark::Counter::OneK::kIs1000); // For GiB : kIs1024
8686
state.counters["docs"] = Counter(double(state.iterations()), benchmark::Counter::kIsRate);
8787
state.counters["tweets"] = Counter(double(tweet_count), benchmark::Counter::kIsRate);
8888
}
8989

90-
BENCHMARK(ondemand_tweets)->Repetitions(REPETITIONS)->ComputeStatistics("max", [](const std::vector<double>& v) -> double {
90+
BENCHMARK(ondemand_tweets)->ComputeStatistics("max", [](const std::vector<double>& v) -> double {
9191
return *(std::max_element(std::begin(v), std::end(v)));
92-
})->DisplayAggregatesOnly(true);
92+
});
9393

9494
} // namespace ondemand_bench
9595

@@ -165,16 +165,16 @@ static void iter_tweets(State &state) {
165165
tweet_count += tweets.size();
166166
}
167167
// Gigabyte: https://en.wikipedia.org/wiki/Gigabyte
168-
state.counters["Gigabytes"] = benchmark::Counter(
168+
state.counters["bytes"] = benchmark::Counter(
169169
double(byte_count), benchmark::Counter::kIsRate,
170170
benchmark::Counter::OneK::kIs1000); // For GiB : kIs1024
171171
state.counters["docs"] = Counter(double(state.iterations()), benchmark::Counter::kIsRate);
172172
state.counters["tweets"] = Counter(double(tweet_count), benchmark::Counter::kIsRate);
173173
}
174174

175-
BENCHMARK(iter_tweets)->Repetitions(REPETITIONS)->ComputeStatistics("max", [](const std::vector<double>& v) -> double {
175+
BENCHMARK(iter_tweets)->ComputeStatistics("max", [](const std::vector<double>& v) -> double {
176176
return *(std::max_element(std::begin(v), std::end(v)));
177-
})->DisplayAggregatesOnly(true);
177+
});
178178

179179
} // namespace iter_bench
180180

@@ -204,15 +204,15 @@ static void sax_tweets(State &state) {
204204
tweets += reader.tweets.size();
205205
}
206206
// Gigabyte: https://en.wikipedia.org/wiki/Gigabyte
207-
state.counters["Gigabytes"] = benchmark::Counter(
207+
state.counters["bytes"] = benchmark::Counter(
208208
double(bytes), benchmark::Counter::kIsRate,
209209
benchmark::Counter::OneK::kIs1000); // For GiB : kIs1024
210210
state.counters["docs"] = Counter(double(state.iterations()), benchmark::Counter::kIsRate);
211211
state.counters["tweets"] = Counter(double(tweets), benchmark::Counter::kIsRate);
212212
}
213-
BENCHMARK(sax_tweets)->Repetitions(REPETITIONS)->ComputeStatistics("max", [](const std::vector<double>& v) -> double {
213+
BENCHMARK(sax_tweets)->ComputeStatistics("max", [](const std::vector<double>& v) -> double {
214214
return *(std::max_element(std::begin(v), std::end(v)));
215-
})->DisplayAggregatesOnly(true);
215+
});
216216

217217
#endif // SIMDJSON_IMPLEMENTATION_HASWELL
218218

@@ -260,17 +260,17 @@ static void dom_tweets(State &state) {
260260
num_tweets += tweets.size();
261261
}
262262
// Gigabyte: https://en.wikipedia.org/wiki/Gigabyte
263-
state.counters["Gigabytes"] = benchmark::Counter(
263+
state.counters["bytes"] = benchmark::Counter(
264264
double(bytes), benchmark::Counter::kIsRate,
265265
benchmark::Counter::OneK::kIs1000); // For GiB : kIs1024
266266
state.counters["docs"] = Counter(double(state.iterations()), benchmark::Counter::kIsRate);
267267
state.counters["tweets"] = Counter(double(num_tweets), benchmark::Counter::kIsRate);
268268
}
269-
BENCHMARK(dom_tweets)->Repetitions(REPETITIONS)->ComputeStatistics("max", [](const std::vector<double>& v) -> double {
269+
BENCHMARK(dom_tweets)->ComputeStatistics("max", [](const std::vector<double>& v) -> double {
270270
return *(std::max_element(std::begin(v), std::end(v)));
271-
})->DisplayAggregatesOnly(true);
271+
});
272272

273-
static void dom_parse(State &state) {
273+
static void parse_tweets(State &state) {
274274
// Load twitter.json to a buffer
275275
padded_string json;
276276
if (auto error = padded_string::load(TWITTER_JSON).get(json)) { cerr << error << endl; return; }
@@ -286,14 +286,14 @@ static void dom_parse(State &state) {
286286
bytes += json.size();
287287
}
288288
// Gigabyte: https://en.wikipedia.org/wiki/Gigabyte
289-
state.counters["Gigabytes"] = benchmark::Counter(
289+
state.counters["bytes"] = benchmark::Counter(
290290
double(bytes), benchmark::Counter::kIsRate,
291291
benchmark::Counter::OneK::kIs1000); // For GiB : kIs1024
292292
state.counters["docs"] = Counter(double(state.iterations()), benchmark::Counter::kIsRate);
293293
}
294-
BENCHMARK(dom_parse)->Repetitions(REPETITIONS)->ComputeStatistics("max", [](const std::vector<double>& v) -> double {
294+
BENCHMARK(parse_tweets)->ComputeStatistics("max", [](const std::vector<double>& v) -> double {
295295
return *(std::max_element(std::begin(v), std::end(v)));
296-
})->DisplayAggregatesOnly(true);
296+
});
297297

298298

299299
/********************
@@ -346,6 +346,7 @@ static void dom_largerandom(State &state) {
346346

347347
// Read
348348
size_t bytes = 0;
349+
size_t points = 0;
349350
simdjson::error_code error;
350351
for (SIMDJSON_UNUSED auto _ : state) {
351352
std::vector<my_point> container;
@@ -358,19 +359,21 @@ static void dom_largerandom(State &state) {
358359
container.emplace_back(my_point{point["x"], point["y"], point["z"]});
359360
}
360361
bytes += json.size();
362+
points += container.size();
361363
benchmark::DoNotOptimize(container.data());
362-
363364
}
365+
364366
// Gigabyte: https://en.wikipedia.org/wiki/Gigabyte
365-
state.counters["Gigabytes"] = benchmark::Counter(
367+
state.counters["bytes"] = benchmark::Counter(
366368
double(bytes), benchmark::Counter::kIsRate,
367369
benchmark::Counter::OneK::kIs1000); // For GiB : kIs1024
368370
state.counters["docs"] = Counter(double(state.iterations()), benchmark::Counter::kIsRate);
371+
state.counters["points"] = Counter(double(points), benchmark::Counter::kIsRate);
369372
}
370373

371-
BENCHMARK(dom_largerandom)->Repetitions(REPETITIONS)->ComputeStatistics("max", [](const std::vector<double>& v) -> double {
374+
BENCHMARK(dom_largerandom)->ComputeStatistics("max", [](const std::vector<double>& v) -> double {
372375
return *(std::max_element(std::begin(v), std::end(v)));
373-
})->DisplayAggregatesOnly(true);
376+
});
374377

375378
#if SIMDJSON_IMPLEMENTATION_HASWELL
376379

@@ -391,27 +394,29 @@ static void ondemand_largerandom(State &state) {
391394

392395
// Read
393396
size_t bytes = 0;
397+
size_t points = 0;
394398
for (SIMDJSON_UNUSED auto _ : state) {
395399
std::vector<my_point> container;
396400
for (ondemand::object point : parser.parse(json)) {
397401
container.emplace_back(my_point{(*point).value(), (*++point).value(), (*++point).value()});
398402
}
399403
bytes += json.size();
404+
points += container.size();
400405
benchmark::DoNotOptimize(container.data());
401-
402406
}
403407
// Gigabyte: https://en.wikipedia.org/wiki/Gigabyte
404-
state.counters["Gigabytes"] = benchmark::Counter(
408+
state.counters["bytes"] = benchmark::Counter(
405409
double(bytes), benchmark::Counter::kIsRate,
406410
benchmark::Counter::OneK::kIs1000); // For GiB : kIs1024
407411
state.counters["docs"] = Counter(double(state.iterations()), benchmark::Counter::kIsRate);
412+
state.counters["points"] = Counter(double(points), benchmark::Counter::kIsRate);
408413
}
409414

410415
SIMDJSON_UNTARGET_REGION
411416

412-
BENCHMARK(ondemand_largerandom)->Repetitions(REPETITIONS)->ComputeStatistics("max", [](const std::vector<double>& v) -> double {
417+
BENCHMARK(ondemand_largerandom)->ComputeStatistics("max", [](const std::vector<double>& v) -> double {
413418
return *(std::max_element(std::begin(v), std::end(v)));
414-
})->DisplayAggregatesOnly(true);
419+
});
415420

416421
SIMDJSON_TARGET_HASWELL
417422

@@ -440,6 +445,7 @@ static void iter_largerandom(State &state) {
440445

441446
// Read
442447
size_t bytes = 0;
448+
size_t points = 0;
443449
for (SIMDJSON_UNUSED auto _ : state) {
444450
std::vector<my_point> container;
445451
auto doc = parser.parse(json);
@@ -452,20 +458,22 @@ static void iter_largerandom(State &state) {
452458
} while (iter.has_next_element());
453459
}
454460
bytes += json.size();
461+
points += container.size();
455462
benchmark::DoNotOptimize(container.data());
456463
}
457464
// Gigabyte: https://en.wikipedia.org/wiki/Gigabyte
458-
state.counters["Gigabytes"] = benchmark::Counter(
465+
state.counters["bytes"] = benchmark::Counter(
459466
double(bytes), benchmark::Counter::kIsRate,
460467
benchmark::Counter::OneK::kIs1000); // For GiB : kIs1024
461468
state.counters["docs"] = Counter(double(state.iterations()), benchmark::Counter::kIsRate);
469+
state.counters["points"] = Counter(double(points), benchmark::Counter::kIsRate);
462470
}
463471

464472
SIMDJSON_UNTARGET_REGION
465473

466-
BENCHMARK(iter_largerandom)->Repetitions(REPETITIONS)->ComputeStatistics("max", [](const std::vector<double>& v) -> double {
474+
BENCHMARK(iter_largerandom)->ComputeStatistics("max", [](const std::vector<double>& v) -> double {
467475
return *(std::max_element(std::begin(v), std::end(v)));
468-
})->DisplayAggregatesOnly(true);
476+
});
469477

470478
/***
471479
* Next we are going to code the SAX approach.
@@ -485,27 +493,22 @@ struct sax_point_reader_visitor {
485493
}
486494

487495
simdjson_really_inline error_code visit_document_start(json_iterator &) { return SUCCESS; }
488-
simdjson_really_inline error_code visit_object_start(json_iterator &) { return SUCCESS; }
489-
simdjson_really_inline error_code visit_key(json_iterator &, const uint8_t *key) {
490-
switch(key[0]) {
491-
case 'x':
492-
idx = 0;
493-
break;
494-
case 'y':
495-
idx = 2;
496-
break;
497-
case 'z':
498-
idx = 3;
499-
break;
500-
}
496+
simdjson_really_inline error_code visit_object_start(json_iterator &) {
497+
idx = 0;
498+
return SUCCESS;
499+
}
500+
simdjson_really_inline error_code visit_key(json_iterator &, const uint8_t *) {
501501
return SUCCESS;
502502
}
503503
simdjson_really_inline error_code visit_primitive(json_iterator &, const uint8_t *value) {
504-
return numberparsing::parse_double(value).get(buffer[idx]);
504+
return numberparsing::parse_double(value).get(buffer[idx++]);
505505
}
506506
simdjson_really_inline error_code visit_array_start(json_iterator &) { return SUCCESS; }
507507
simdjson_really_inline error_code visit_array_end(json_iterator &) { return SUCCESS; }
508-
simdjson_really_inline error_code visit_object_end(json_iterator &) { return SUCCESS; }
508+
simdjson_really_inline error_code visit_object_end(json_iterator &) {
509+
points.emplace_back(my_point{buffer[0], buffer[1], buffer[2]});
510+
return SUCCESS;
511+
}
509512
simdjson_really_inline error_code visit_document_end(json_iterator &) { return SUCCESS; }
510513
simdjson_really_inline error_code visit_empty_array(json_iterator &) { return SUCCESS; }
511514
simdjson_really_inline error_code visit_empty_object(json_iterator &) { return SUCCESS; }
@@ -583,20 +586,23 @@ static void sax_largerandom(State &state) {
583586

584587
// Read
585588
size_t bytes = 0;
589+
size_t points = 0;
586590
for (SIMDJSON_UNUSED auto _ : state) {
587591
if (auto error = reader.read_points(json)) { throw error; }
588592
bytes += json.size();
593+
points += reader.points.size();
589594
benchmark::DoNotOptimize(reader.points.data());
590595
}
591596
// Gigabyte: https://en.wikipedia.org/wiki/Gigabyte
592-
state.counters["Gigabytes"] = benchmark::Counter(
597+
state.counters["bytes"] = benchmark::Counter(
593598
double(bytes), benchmark::Counter::kIsRate,
594599
benchmark::Counter::OneK::kIs1000); // For GiB : kIs1024
595600
state.counters["docs"] = Counter(double(state.iterations()), benchmark::Counter::kIsRate);
601+
state.counters["points"] = Counter(double(points), benchmark::Counter::kIsRate);
596602
}
597-
BENCHMARK(sax_largerandom)->Repetitions(REPETITIONS)->ComputeStatistics("max", [](const std::vector<double>& v) -> double {
603+
BENCHMARK(sax_largerandom)->ComputeStatistics("max", [](const std::vector<double>& v) -> double {
598604
return *(std::max_element(std::begin(v), std::end(v)));
599-
})->DisplayAggregatesOnly(true);
605+
});
600606

601607
#endif // SIMDJSON_IMPLEMENTATION_HASWELL
602608

0 commit comments

Comments
 (0)