So-Bogus
A c++ sparse block matrix library aimed at Second Order cone problems
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Timer.hpp
1 /*
2  * This file is part of bogus, a C++ sparse block matrix library.
3  *
4  * Copyright 2013 Gilles Daviet <gdaviet@gmail.com>
5  *
6  * This Source Code Form is subject to the terms of the Mozilla Public
7  * License, v. 2.0. If a copy of the MPL was not distributed with this
8  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 */
10 
11 #ifndef BOGUS_TIMER_HPP
12 #define BOGUS_TIMER_HPP
13 
14 #ifdef WIN32
15 #include <Winbase.h>
16 #else
17 #include <sys/time.h>
18 #endif
19 
20 namespace bogus
21 {
22 
24 class Timer {
25 public:
26  Timer()
27  {
28 #ifdef WIN32
29  LARGE_INTEGER proc_freq;
30  ::QueryPerformanceFrequency(&proc_freq) ;
31  m_freq = proc_freq.QuadPart ;
32 #endif
33  reset() ;
34  }
35 
37  double elapsed()
38  {
39 #ifdef WIN32
40  LARGE_INTEGER stop;
41  ::QueryPerformanceCounter(&stop);
42  return (( stop.QuadPart - m_start.QuadPart) / m_frequency);
43 #else
44  struct timeval stop ;
45  gettimeofday( &stop, 0 ) ;
46  return stop.tv_sec - m_start.tv_sec
47  + 1.e-6 * ( stop.tv_usec - m_start.tv_usec ) ;
48 #endif
49  }
50 
52  void reset()
53  {
54 #ifdef WIN32
55  ::QueryPerformanceCounter(&m_start);
56 #else
57  gettimeofday( &m_start, 0 ) ;
58 #endif
59  }
60 
61 private:
62 
63 #ifdef WIN32
64  double m_freq ;
65  LARGE_INTEGER m_start;
66 #else
67  struct timeval m_start ;
68 #endif
69 
70 };
71 
72 } //namespace bogus
73 
74 #endif
void reset()
Restarts the timer.
Definition: Timer.hpp:52
double elapsed()
Resturns the elapsed time, in seconds, since the last call to reset()
Definition: Timer.hpp:37
Simple timer class. Starts when constructed.
Definition: Timer.hpp:24