MCPcopy Create free account
hub / github.com/Bziyue/SplineTrajectory / runBenchmark

Function runBenchmark

test_Grad.cpp:29–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27
28template <typename Func>
29BenchmarkStats runBenchmark(const Func &func, int iters, int repeats = 7, int warmup_iters = 200)
30{
31 for (int i = 0; i < warmup_iters; ++i)
32 {
33 func();
34 }
35
36 vector<double> samples_us;
37 samples_us.reserve(repeats);
38 for (int r = 0; r < repeats; ++r)
39 {
40 const auto t0 = high_resolution_clock::now();
41 for (int i = 0; i < iters; ++i)
42 {
43 func();
44 }
45 const double avg_us =
46 duration_cast<microseconds>(high_resolution_clock::now() - t0).count() / static_cast<double>(iters);
47 samples_us.push_back(avg_us);
48 }
49
50 BenchmarkStats stats;
51 stats.mean_us = accumulate(samples_us.begin(), samples_us.end(), 0.0) / static_cast<double>(samples_us.size());
52 stats.min_us = *min_element(samples_us.begin(), samples_us.end());
53
54 double var = 0.0;
55 for (const double x : samples_us)
56 {
57 const double d = x - stats.mean_us;
58 var += d * d;
59 }
60 stats.std_us = sqrt(var / static_cast<double>(samples_us.size()));
61 return stats;
62}
63
64void printHeader(const string &title)
65{

Callers 3

testCubicFunction · 0.85
testQuinticFunction · 0.85
testSepticFunction · 0.85

Calls 3

reserveMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected