GeNN  4.9.0
GPU enhanced Neuronal Networks (GeNN)
include/spineml/simulator/timer.h
Go to the documentation of this file.
1 #pragma once
2 
3 // Standard C++ includes
4 #include <chrono>
5 #include <iostream>
6 #include <string>
7 
8 // SpineML common includes
9 #include "spineMLLogging.h"
10 
11 //------------------------------------------------------------------------
12 // SpineMLSimulator::Timer
13 //------------------------------------------------------------------------
14 namespace SpineMLSimulator
15 {
16 class Timer
17 {
18 public:
19  Timer(const std::string &title) : m_Start(std::chrono::high_resolution_clock::now()), m_Title(title)
20  {
21  }
22 
24  {
25  LOGI_SPINEML << m_Title << get() << std::endl;
26  }
27 
28  //------------------------------------------------------------------------
29  // Public API
30  //------------------------------------------------------------------------
31  double get() const
32  {
33  auto now = std::chrono::high_resolution_clock::now();
34  std::chrono::duration<double, std::milli> duration = now - m_Start;
35  return duration.count();
36  }
37 
38 private:
39  //------------------------------------------------------------------------
40  // Members
41  //------------------------------------------------------------------------
42  std::chrono::time_point<std::chrono::high_resolution_clock> m_Start;
43  std::string m_Title;
44 };
45 
46 //------------------------------------------------------------------------
47 // SpineMLSimulator::TimerAccumulate
48 //------------------------------------------------------------------------
50 {
51 public:
52  TimerAccumulate(double &accumulator) : m_Start(std::chrono::high_resolution_clock::now()), m_Accumulator(accumulator)
53  {
54  }
55 
57  {
58  m_Accumulator += get();
59  }
60 
61  //------------------------------------------------------------------------
62  // Public API
63  //------------------------------------------------------------------------
64  double get() const
65  {
66  auto now = std::chrono::high_resolution_clock::now();
67  std::chrono::duration<double, std::milli> duration = now - m_Start;
68  return duration.count();
69  }
70 
71 private:
72  //------------------------------------------------------------------------
73  // Members
74  //------------------------------------------------------------------------
75  std::chrono::time_point<std::chrono::high_resolution_clock> m_Start;
76  double &m_Accumulator;
77 };
78 }
Definition: include/spineml/simulator/timer.h:16
STL namespace.
TimerAccumulate(double &accumulator)
Definition: include/spineml/simulator/timer.h:52
Definition: include/spineml/simulator/timer.h:49
Definition: connectors.h:25
~TimerAccumulate()
Definition: include/spineml/simulator/timer.h:56
Timer(const std::string &title)
Definition: include/spineml/simulator/timer.h:19
~Timer()
Definition: include/spineml/simulator/timer.h:23