Skip to content

Commit

Permalink
Fix randomness error in Handler benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Bronek committed Oct 16, 2023
1 parent 90dfe7b commit 18503e7
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/test/rpc/Handler_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,25 @@ class Handler_test : public beast::unit_test::suite
time(std::size_t n, auto f, auto prng)
{
assert(n > 0);
// Prepare randomness cache away from performance measurements
std::vector<decltype(prng())> randomness;
randomness.reserve(n + 6);
for (std::size_t i = 0; i < n; i += 6)
{
randomness.push_back(prng());
}

double sum = 0;
double sum_squared = 0;
std::size_t j = 0;
while (j < n)
{
// Generate 20 inputs upfront, separated from the inner loop
std::array<decltype(prng()), 20> inputs = {};
for (auto& i : inputs)
{
i = prng();
}

// Take 20 samples and throw away 7 from each end, using middle 6
std::array<long, 20> samples = {};
for (auto& s : samples)
for (std::size_t k = 0; k < 20; ++k)
{
auto start = std::chrono::high_resolution_clock::now();
f(randomness[j]);
s = (std::chrono::high_resolution_clock::now() - start).count();
auto start = std::chrono::steady_clock::now();
f(inputs[k]);
samples[k] = (std::chrono::steady_clock::now() - start).count();
}

std::sort(samples.begin(), samples.end());
Expand Down

0 comments on commit 18503e7

Please sign in to comment.