-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtimer.h
66 lines (49 loc) · 1.47 KB
/
timer.h
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
--------------------------------------------------------------------------------
- Module : timer.h
- Description : A nice timer class.
- Author : Tim Zaman, 18-FEB-2016
--------------------------------------------------------------------------------
*/
/*
Copyright (c) 2016 Tim Zaman
Permission to use, copy, modify, distribute, and sell this software
for any purpose is hereby granted without fee, provided
that (i) the above copyright notices and this permission notice appear in
all copies of the software and related documentation.
THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef TIM_TIMER_h
#define TIM_TIMER_h
#pragma once
#include <iostream>
#include <chrono>
#include <ctime>
/*!
* \brief Timer
*
* Timer function that can be used to benchmark code speed.
* \author Tim Zaman
*
*/
class timer {
public:
timer(){
this->start = std::chrono::system_clock::now();
}
void tic(){
this->start = std::chrono::system_clock::now();
}
double toc(){
end = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = end-start;
return double (elapsed_seconds);
}
void toc(std::string strLabel){
std::cout << strLabel << " took " << toc() << " ms." << std::endl;
}
private:
std::chrono::time_point<std::chrono::system_clock> start, end;
}