run benchmark once before measuring

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.
This commit is contained in:
Dmitry Arkhipov 2023-11-06 17:20:04 +03:00
parent 3b8f86cb05
commit b9c830781f

View File

@ -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);