blob: 57762958408dceb2e9a6dc15d9ffc8c10d46ab35 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
#pragma once
#include <vector>
#include <thread>
#include <numeric>
static constexpr int N_RUNS = 100;
// Utility function for time execution calculation
template <typename F, typename... Args>
double get_execution_time(F func, Args &&...args) {
std::vector<float> execution_times;
for (int i = 0; i < N_RUNS; i++) {
auto start = std::chrono::high_resolution_clock::now();
func(std::forward<Args>(args)...);
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> ms = end - start;
execution_times.emplace_back(ms.count());
}
// Calculate average
return std::reduce(execution_times.begin(), execution_times.end()) /
execution_times.size();
}
|