Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bench runner can run external command #1028

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading