PODIO v00-16-03
An Event-Data-Model Toolkit for High Energy Physics Experiments
Loading...
Searching...
No Matches
BenchmarkUtil.h
Go to the documentation of this file.
1#ifndef PODIO_BENCHMARKUTIL_H
2#define PODIO_BENCHMARKUTIL_H
3
4#include <chrono>
5#include <functional>
6#include <utility>
7
8namespace podio::benchmark {
9using ClockT = std::chrono::high_resolution_clock;
10
11/**
12 * Run a member function and record the duration. Return the result and the
13 * duration in a pair.
14 */
15template <class Obj, typename MemberFunc, typename... Args>
16inline std::pair<std::invoke_result_t<MemberFunc, Obj, Args...>, ClockT::duration>
17run_member_timed(Obj& obj, MemberFunc func, Args&&... args) {
18 const auto start = ClockT::now();
19 const auto retval = std::invoke(func, obj, std::forward<Args>(args)...);
20 const auto end = ClockT::now();
21
22 return std::make_pair(retval, end - start);
23}
24
25/**
26 * Run a member function without return value and record the duration. Return
27 * the duration and only use the side-effects of the member function. Can't get
28 * this to work in the above version with a void return value, so that is why we
29 * have a dedicated function for void functions here.
30 */
31template <class Obj, typename MemberFunc, typename... Args>
32inline ClockT::duration run_void_member_timed(Obj& obj, MemberFunc func, Args&&... args) {
33 const auto start = ClockT::now();
34 std::invoke(func, obj, std::forward<Args>(args)...);
35 const auto end = ClockT::now();
36
37 return end - start;
38}
39
40} // namespace podio::benchmark
41
42#endif
ClockT::duration run_void_member_timed(Obj &obj, MemberFunc func, Args &&... args)
Definition: BenchmarkUtil.h:32
std::chrono::high_resolution_clock ClockT
Definition: BenchmarkUtil.h:9
std::pair< std::invoke_result_t< MemberFunc, Obj, Args... >, ClockT::duration > run_member_timed(Obj &obj, MemberFunc func, Args &&... args)
Definition: BenchmarkUtil.h:17