-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeasure.h
More file actions
26 lines (22 loc) · 842 Bytes
/
measure.h
File metadata and controls
26 lines (22 loc) · 842 Bytes
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
//
// Created by Agustin Gianni (agustin.gianni@gmail.com) on 11/19/16.
//
#ifndef THREADPROFILER_MEASURE_H
#define THREADPROFILER_MEASURE_H
#include <unistd.h>
#include <chrono>
#include <string>
#include <iostream>
// Measure the time it takes to execute a given function.
template<typename time_type=std::chrono::milliseconds, typename clock=std::chrono::steady_clock>
struct measure {
template<typename F, typename ...Args>
static std::pair<typename std::result_of<F(Args...)>::type, typename time_type::rep> execution(F func, Args&&... args) {
auto t0 = clock::now();
auto ret = func(std::forward<Args>(args)...);
auto t1 = clock::now();
auto delta = std::chrono::duration_cast<time_type>(t1 - t0);
return std::make_pair(ret, delta.count());
}
};
#endif //THREADPROFILER_MEASURE_H