Skip to content

Commit e4e89fe

Browse files
authored
Fix parse benchmarker (simdjson#554)
* Fix parse benchmarker * Make CI fail when parse doesn't work
1 parent 24551db commit e4e89fe

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

benchmark/benchmarker.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ struct benchmarker {
298298
// Allocate document::parser
299299
collector.start();
300300
document::parser parser;
301-
error_code error = parser.set_capacity(json.size());
301+
bool alloc_ok = parser.allocate_capacity(json.size());
302302
event_count allocate_count = collector.end();
303303
allocate_stage << allocate_count;
304304
// Run it once to get hot buffers
@@ -309,14 +309,14 @@ struct benchmarker {
309309
}
310310
}
311311

312-
if (error) {
312+
if (!alloc_ok) {
313313
exit_error(string("Unable to allocate_stage ") + to_string(json.size()) + " bytes for the JSON result.");
314314
}
315315
verbose() << "[verbose] allocated memory for parsed JSON " << endl;
316316

317317
// Stage 1 (find structurals)
318318
collector.start();
319-
error = active_implementation->stage1((const uint8_t *)json.data(), json.size(), parser, false);
319+
error_code error = active_implementation->stage1((const uint8_t *)json.data(), json.size(), parser, false);
320320
event_count stage1_count = collector.end();
321321
stage1 << stage1_count;
322322
if (error) {

benchmark/perfdiff.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,27 @@
77
#include <array>
88
#include <algorithm>
99
#include <vector>
10+
#include <cmath>
1011

1112
#ifdef _WIN32
1213
#define popen _popen
1314
#define pclose _pclose
1415
#endif
1516

17+
int closepipe(FILE *pipe) {
18+
int exit_code = pclose(pipe);
19+
if (exit_code != EXIT_SUCCESS) {
20+
std::cerr << "Error " << exit_code << " running benchmark command!" << std::endl;
21+
exit(EXIT_FAILURE);
22+
};
23+
return exit_code;
24+
}
25+
1626
std::string exec(const char* cmd) {
27+
std::cerr << cmd << std::endl;
1728
std::array<char, 128> buffer;
1829
std::string result;
19-
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
30+
std::unique_ptr<FILE, decltype(&closepipe)> pipe(popen(cmd, "r"), closepipe);
2031
if (!pipe) {
2132
throw std::runtime_error("popen() failed!");
2233
}
@@ -43,6 +54,10 @@ double readThroughput(std::string parseOutput) {
4354
result += std::stod(line.substr(pos));
4455
numResults++;
4556
}
57+
if (numResults == 0) {
58+
std::cerr << "No results returned from benchmark command!" << std::endl;
59+
exit(EXIT_FAILURE);
60+
}
4661
return result / numResults;
4762
}
4863

0 commit comments

Comments
 (0)