svMultiPhysics
Loading...
Searching...
No Matches
Timer.h
1// SPDX-FileCopyrightText: Copyright (c) Stanford University, The Regents of the University of California, and others.
2// SPDX-License-Identifier: BSD-3-Clause
3
4#ifndef TIMER_H
5#define TIMER_H
6
7#include <chrono>
8#include <iostream>
9#include <string>
10
11/// @brief Keep track of time
12class Timer
13{
14 public:
15
16 double get_elapsed_time()
17 {
18 return get_time() - current_time;
19 }
20
21 double get_time()
22 {
23 auto now = std::chrono::system_clock::now();
24 auto now_ms = std::chrono::time_point_cast<std::chrono::milliseconds>(now);
25
26 auto value = now_ms.time_since_epoch();
27 auto duration = value.count() / 1000.0;
28 return static_cast<double>(duration);
29 }
30
31 void set_time()
32 {
33 current_time = get_time();
34 }
35
36 double current_time;
37};
38
39#endif
40
Keep track of time.
Definition Timer.h:13