Fix parse benchmarker (#554)

* Fix parse benchmarker

* Make CI fail when parse doesn't work
This commit is contained in:
John Keiser 2020-03-13 13:19:21 -07:00 committed by GitHub
parent 24551db0c8
commit e4e89fe27a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 4 deletions

View File

@ -298,7 +298,7 @@ struct benchmarker {
// Allocate document::parser
collector.start();
document::parser parser;
error_code error = parser.set_capacity(json.size());
bool alloc_ok = parser.allocate_capacity(json.size());
event_count allocate_count = collector.end();
allocate_stage << allocate_count;
// Run it once to get hot buffers
@ -309,14 +309,14 @@ struct benchmarker {
}
}
if (error) {
if (!alloc_ok) {
exit_error(string("Unable to allocate_stage ") + to_string(json.size()) + " bytes for the JSON result.");
}
verbose() << "[verbose] allocated memory for parsed JSON " << endl;
// Stage 1 (find structurals)
collector.start();
error = active_implementation->stage1((const uint8_t *)json.data(), json.size(), parser, false);
error_code error = active_implementation->stage1((const uint8_t *)json.data(), json.size(), parser, false);
event_count stage1_count = collector.end();
stage1 << stage1_count;
if (error) {

View File

@ -7,16 +7,27 @@
#include <array>
#include <algorithm>
#include <vector>
#include <cmath>
#ifdef _WIN32
#define popen _popen
#define pclose _pclose
#endif
int closepipe(FILE *pipe) {
int exit_code = pclose(pipe);
if (exit_code != EXIT_SUCCESS) {
std::cerr << "Error " << exit_code << " running benchmark command!" << std::endl;
exit(EXIT_FAILURE);
};
return exit_code;
}
std::string exec(const char* cmd) {
std::cerr << cmd << std::endl;
std::array<char, 128> buffer;
std::string result;
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
std::unique_ptr<FILE, decltype(&closepipe)> pipe(popen(cmd, "r"), closepipe);
if (!pipe) {
throw std::runtime_error("popen() failed!");
}
@ -43,6 +54,10 @@ double readThroughput(std::string parseOutput) {
result += std::stod(line.substr(pos));
numResults++;
}
if (numResults == 0) {
std::cerr << "No results returned from benchmark command!" << std::endl;
exit(EXIT_FAILURE);
}
return result / numResults;
}