Sleipnir C++ API
Loading...
Searching...
No Matches
Profiler.hpp
Go to the documentation of this file.
1// Copyright (c) Sleipnir contributors
2
3#pragma once
4
5#include <chrono>
6
7namespace sleipnir {
8
13class Profiler {
14 public:
18 void StartSetup() { m_setupStartTime = std::chrono::steady_clock::now(); }
19
23 void StopSetup() {
24 m_setupDuration = std::chrono::steady_clock::now() - m_setupStartTime;
25 }
26
30 void StartSolve() { m_solveStartTime = std::chrono::steady_clock::now(); }
31
36 void StopSolve() {
37 auto now = std::chrono::steady_clock::now();
38 ++m_solveMeasurements;
39 m_averageSolveDuration =
40 (m_solveMeasurements - 1.0) / m_solveMeasurements *
41 m_averageSolveDuration +
42 1.0 / m_solveMeasurements * (now - m_solveStartTime);
43 }
44
48 double SetupDuration() const {
49 using std::chrono::duration_cast;
50 using std::chrono::nanoseconds;
51 return duration_cast<nanoseconds>(m_setupDuration).count() / 1e6;
52 }
53
57 int SolveMeasurements() const { return m_solveMeasurements; }
58
62 double AverageSolveDuration() const {
63 using std::chrono::duration_cast;
64 using std::chrono::nanoseconds;
65 return duration_cast<nanoseconds>(m_averageSolveDuration).count() / 1e6;
66 }
67
68 private:
69 std::chrono::steady_clock::time_point m_setupStartTime;
70 std::chrono::duration<double> m_setupDuration{0.0};
71
72 int m_solveMeasurements = 0;
73 std::chrono::duration<double> m_averageSolveDuration{0.0};
74 std::chrono::steady_clock::time_point m_solveStartTime;
75};
76
77} // namespace sleipnir
Definition Profiler.hpp:13
void StopSolve()
Definition Profiler.hpp:36
void StartSetup()
Definition Profiler.hpp:18
double SetupDuration() const
Definition Profiler.hpp:48
int SolveMeasurements() const
Definition Profiler.hpp:57
double AverageSolveDuration() const
Definition Profiler.hpp:62
void StartSolve()
Definition Profiler.hpp:30
void StopSetup()
Definition Profiler.hpp:23
Definition Expression.hpp:18
IntrusiveSharedPtr< T > AllocateIntrusiveShared(Alloc alloc, Args &&... args)
Definition IntrusiveSharedPtr.hpp:275