Skip to content

Commit

Permalink
run benchmark onces before measuring
Browse files Browse the repository at this point in the history
This puts the input data into memory, which puts multiple trials on
equal ground. Without it the first trial is often radically different
from the following trials.
  • Loading branch information
grisumbras committed Nov 6, 2023
1 parent 3b8f86c commit c3a6399
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions bench/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,20 +179,23 @@ bench(
for(unsigned j = 0; j < vi.size(); ++j)
{
trial.clear();
std::size_t repeat = 1000;
std::size_t repeat = 1;
auto const f = [&]
{
if(verb == "Parse")
return vi[j]->parse(vf[i].text, repeat);
else if(verb == "Serialize")
return vi[j]->serialize(vf[i].text, repeat);

return clock_type::duration();
};
// helps with the caching, which reduces noise
f();

repeat = 1000;
for(unsigned k = 0; k < Trials; ++k)
{
auto result = run_for(
std::chrono::seconds(5),
[&]
{
if(verb == "Parse")
return vi[j]->parse(vf[i].text, repeat);
else if(verb == "Serialize")
return vi[j]->serialize(vf[i].text, repeat);

return clock_type::duration();
});
auto result = run_for(std::chrono::seconds(5), f);
result.calls *= repeat;
result.mbs = megabytes_per_second(
vf[i], result.calls, result.millis);
Expand Down

0 comments on commit c3a6399

Please sign in to comment.