NimbleSM
NimbleSM is a solid mechanics simulation code for dynamic systems
Loading...
Searching...
No Matches
nimble::quanta::stopwatch Struct Reference

#include <nimble.quanta.stopwatch.h>

Public Types

typedef decltype(std::chrono::high_resolution_clock::now()) time
 
typedef std::chrono::duration< double, std::ratio< 1, 1 > > seconds
 
typedef std::chrono::duration< double, std::milli > milliseconds
 
typedef std::chrono::duration< double, std::micro > microseconds
 
typedef decltype((time{} - time{}).count()) nanoseconds
 
typedef decltype((time{} - time{})) duration
 

Public Member Functions

nanoseconds age_nano ()
 
double age_micro ()
 
double age_milli ()
 
double age ()
 
void reset ()
 

Static Public Member Functions

template<class Function, class... Args>
static double timefunction (Function &&f, Args &&... inputs)
 
static std::string get_nanosecond_timestamp ()
 
static std::string get_microsecond_timestamp ()
 
static std::string get_millisecond_timestamp ()
 

Public Attributes

time _start = std::chrono::high_resolution_clock::now()
 

Member Typedef Documentation

◆ duration

typedef decltype((time{} - time{})) nimble::quanta::stopwatch::duration

◆ microseconds

typedef std::chrono::duration<double, std::micro> nimble::quanta::stopwatch::microseconds

◆ milliseconds

typedef std::chrono::duration<double, std::milli> nimble::quanta::stopwatch::milliseconds

◆ nanoseconds

typedef decltype((time{} - time{}).count()) nimble::quanta::stopwatch::nanoseconds

◆ seconds

typedef std::chrono::duration<double, std::ratio<1, 1> > nimble::quanta::stopwatch::seconds

◆ time

typedef decltype(std::chrono::high_resolution_clock::now()) nimble::quanta::stopwatch::time

Member Function Documentation

◆ age()

double nimble::quanta::stopwatch::age ( )
inline
77 {
78 return seconds(std::chrono::high_resolution_clock::now() - _start).count();
79 }
time _start
Definition nimble.quanta.stopwatch.h:59
std::chrono::duration< double, std::ratio< 1, 1 > > seconds
Definition nimble.quanta.stopwatch.h:54

◆ age_micro()

double nimble::quanta::stopwatch::age_micro ( )
inline
67 {
68 return microseconds(std::chrono::high_resolution_clock::now() - _start).count();
69 }
std::chrono::duration< double, std::micro > microseconds
Definition nimble.quanta.stopwatch.h:56

◆ age_milli()

double nimble::quanta::stopwatch::age_milli ( )
inline
72 {
73 return milliseconds(std::chrono::high_resolution_clock::now() - _start).count();
74 }
std::chrono::duration< double, std::milli > milliseconds
Definition nimble.quanta.stopwatch.h:55

◆ age_nano()

nanoseconds nimble::quanta::stopwatch::age_nano ( )
inline
62 {
63 return (std::chrono::high_resolution_clock::now() - _start).count();
64 }

◆ get_microsecond_timestamp()

static std::string nimble::quanta::stopwatch::get_microsecond_timestamp ( )
inlinestatic
120 {
121 auto epoch_duration = std::chrono::high_resolution_clock::now().time_since_epoch();
122 auto duration_in_seconds = std::chrono::duration_cast<std::chrono::seconds>(epoch_duration);
123 auto microseconds =
124 (std::chrono::duration_cast<std::chrono::microseconds>(epoch_duration - duration_in_seconds).count());
125 std::time_t t = duration_in_seconds.count();
126 char buffer[100]{};
127 size_t end;
128 if ((end = std::strftime(buffer, 100, "%Y.%m.%d.%H.%M.%S.", std::localtime(&t)))) {
129 buffer[end] = '0' + (microseconds / 100000 % 10);
130 buffer[end + 1] = '0' + (microseconds / 10000 % 10);
131 buffer[end + 2] = '0' + (microseconds / 1000 % 10);
132 buffer[end + 3] = '0' + (microseconds / 100 % 10);
133 buffer[end + 4] = '0' + (microseconds / 10 % 10);
134 buffer[end + 5] = '0' + (microseconds % 10);
135 buffer[end + 6] = '\0';
136 }
137 return buffer;
138 }

◆ get_millisecond_timestamp()

static std::string nimble::quanta::stopwatch::get_millisecond_timestamp ( )
inlinestatic
141 {
142 auto epoch_duration = std::chrono::high_resolution_clock::now().time_since_epoch();
143 auto duration_in_seconds = std::chrono::duration_cast<std::chrono::seconds>(epoch_duration);
144 auto milliseconds =
145 (std::chrono::duration_cast<std::chrono::milliseconds>(epoch_duration - duration_in_seconds).count());
146 std::time_t t = duration_in_seconds.count();
147 char buffer[100]{};
148 size_t end;
149 if ((end = std::strftime(buffer, 100, "%Y.%m.%e.%H.%M.%S.", std::localtime(&t)))) {
150 size_t milliseconds = (std::chrono::duration_cast<std::chrono::milliseconds>(
151 std::chrono::high_resolution_clock::now().time_since_epoch())
152 .count());
153 buffer[end] = '0' + (milliseconds / 100 % 10);
154 buffer[end + 1] = '0' + (milliseconds / 10 % 10);
155 buffer[end + 2] = '0' + (milliseconds % 10);
156 buffer[end + 3] = '\0';
157 }
158 return buffer;
159 }

◆ get_nanosecond_timestamp()

static std::string nimble::quanta::stopwatch::get_nanosecond_timestamp ( )
inlinestatic
96 {
97 auto epoch_duration = std::chrono::high_resolution_clock::now().time_since_epoch();
98 auto duration_in_seconds = std::chrono::duration_cast<std::chrono::seconds>(epoch_duration);
99 auto nanoseconds =
100 (std::chrono::duration_cast<std::chrono::nanoseconds>(epoch_duration - duration_in_seconds).count());
101 std::time_t t = duration_in_seconds.count();
102 char buffer[100]{};
103 size_t end;
104 if ((end = std::strftime(buffer, 100, "%Y.%m.%e.%H.%M.%S.", std::localtime(&t)))) {
105 buffer[end] = '0' + (nanoseconds / 100000000 % 10);
106 buffer[end + 1] = '0' + (nanoseconds / 10000000 % 10);
107 buffer[end + 2] = '0' + (nanoseconds / 1000000 % 10);
108 buffer[end + 3] = '0' + (nanoseconds / 100000 % 10);
109 buffer[end + 4] = '0' + (nanoseconds / 10000 % 10);
110 buffer[end + 5] = '0' + (nanoseconds / 1000 % 10);
111 buffer[end + 6] = '0' + (nanoseconds / 100 % 10);
112 buffer[end + 7] = '0' + (nanoseconds / 10 % 10);
113 buffer[end + 8] = '0' + (nanoseconds % 10);
114 buffer[end + 9] = '\0';
115 }
116 return buffer;
117 }
decltype((time{} - time{}).count()) nanoseconds
Definition nimble.quanta.stopwatch.h:57

◆ reset()

void nimble::quanta::stopwatch::reset ( )
inline
82 {
83 _start = std::chrono::high_resolution_clock::now();
84 }

◆ timefunction()

template<class Function, class... Args>
static double nimble::quanta::stopwatch::timefunction ( Function && f,
Args &&... inputs )
inlinestatic
88 {
89 stopwatch s;
90 s.reset();
91 f(std::forward<Args>(inputs)...);
92 return s.age();
93 }

Member Data Documentation

◆ _start

time nimble::quanta::stopwatch::_start = std::chrono::high_resolution_clock::now()

The documentation for this struct was generated from the following file: