Skip to content

Commit

Permalink
bench runner can run external command
Browse files Browse the repository at this point in the history
  • Loading branch information
grisumbras committed Jul 19, 2024
1 parent baff1cb commit 5ff581c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions bench/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ std::stringstream strout;
parse_options popts;
bool with_file_io = false;

char const* external_command = nullptr;

#if defined(__clang__)
string_view toolset = "clang";
#elif defined(__GNUC__)
Expand Down Expand Up @@ -173,6 +175,22 @@ print_prefix(
arch << "," << impl.name();
}

void
run_external(char const* op, file_item const& f)
{
if( !external_command )
return;

std::string command = external_command;
command += ' ';
command += op;
command += ' ';
command += toolset;
command += ' ';
command += f.name;
(void)std::system( command.c_str() );
}

void
bench(
string_view verb,
Expand Down Expand Up @@ -203,7 +221,10 @@ bench(
repeat = 1000;
for(unsigned k = 0; k < Trials; ++k)
{
run_external("start", vf[i]);
auto result = run_for(std::chrono::seconds(5), f);
run_external("finish", vf[i]);

result.calls *= repeat;
result.mbs = megabytes_per_second(
vf[i], result.calls, result.millis);
Expand Down Expand Up @@ -1159,6 +1180,8 @@ main(
return 4;
}

external_command = std::getenv("BOOST_JSON_BENCH_EXTERNAL_COMMAND");

file_list vf;

for( int i = 1; i < argc; ++i )
Expand Down

0 comments on commit 5ff581c

Please sign in to comment.