Assignments
Assignments
timer.h
Go to the documentation of this file.
1/*
2Copyright (c) 2019, Michael Kazhdan
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without modification,
6are permitted provided that the following conditions are met:
7
8Redistributions of source code must retain the above copyright notice, this list of
9conditions and the following disclaimer. Redistributions in binary form must reproduce
10the above copyright notice, this list of conditions and the following disclaimer
11in the documentation and/or other materials provided with the distribution.
12
13Neither the name of the Johns Hopkins University nor the names of its contributors
14may be used to endorse or promote products derived from this software without specific
15prior written permission.
16
17THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
18EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES
19OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
20SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
22TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26DAMAGE.
27*/
28
29#ifndef TIMER_INCLUDED
30#define TIMER_INCLUDED
31
32#include <chrono>
33namespace Util
34{
36 class Timer
37 {
39 std::chrono::high_resolution_clock::time_point _start;
40
41 public:
43 Timer( void ){ _start = std::chrono::high_resolution_clock::now(); }
44
46 double elapsed( void ) const
47 {
48 std::chrono::high_resolution_clock::time_point now = std::chrono::high_resolution_clock::now();
49 std::chrono::duration< double > duration = std::chrono::duration_cast< std::chrono::duration< double > >( now - _start );
50 return duration.count();
51 };
52
54 void reset( void ){ _start = std::chrono::high_resolution_clock::now(); }
55 };
56}
57#endif // TIMER_INCLUDED
Definition: timer.h:37
Timer(void)
Definition: timer.h:43
double elapsed(void) const
Definition: timer.h:46
void reset(void)
Definition: timer.h:54
std::chrono::high_resolution_clock::time_point _start
Definition: timer.h:39
Definition: algebra.h:7