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 365b46e
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions bench/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <memory>
#include <numeric>
#include <cstdio>
#include <sstream>
#include <vector>

#include "test_suite.hpp"
Expand All @@ -57,6 +58,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 +176,40 @@ print_prefix(
arch << "," << impl.name();
}

void
start_external(file_item const& f, any_impl const& i, string_view verb)
{
if( !external_command )
return;

std::stringstream command;
command << external_command << " Starting \"";
print_prefix(command, f, i, verb ) << '"';
std::string const command_s = command.str();
(void)std::system( command_s.c_str() );
}

void
finish_external(
file_item const& f,
any_impl const& i,
string_view verb,
sample const& result)
{
if( !external_command )
return;

std::stringstream command;
command << external_command << " Completed \"";
print_prefix(command, f, i, verb )
<< "," << result.calls
<< "," << result.millis
<< "," << result.mbs
<< '"';
std::string const command_s = command.str();
(void)std::system( command_s.c_str() );
}

void
bench(
string_view verb,
Expand Down Expand Up @@ -203,7 +240,10 @@ bench(
repeat = 1000;
for(unsigned k = 0; k < Trials; ++k)
{
start_external(vf[i], *vi[j], verb);
auto result = run_for(std::chrono::seconds(5), f);
finish_external(vf[i], *vi[j], verb, result);

result.calls *= repeat;
result.mbs = megabytes_per_second(
vf[i], result.calls, result.millis);
Expand Down Expand Up @@ -1159,6 +1199,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 365b46e

Please sign in to comment.