mueller_stopwatch #30
@ -8,8 +8,9 @@
|
||||
#include <cstdint>
|
||||
#include <sys/time.h>
|
||||
|
||||
|
||||
typedef uint32_t millis_t;
|
||||
typedef double seconds_t;
|
||||
//! Don't use these for time points, type is not large enough for UNIX epoch.
|
||||
gaisser
commented
Seconds are converted to double in timevalOperations::toDouble(elapsedTime), this would not fit to the float type. Seconds are converted to double in timevalOperations::toDouble(elapsedTime), this would not fit to the float type.
muellerr
commented
second is double now second is double now
gaisser
commented
I still don't think that those typedefs are a good idea. Maybe we should stick to the types timeval or timespec uses or even use the types C++11 uses in duration Link. I still don't think that those typedefs are a good idea. Maybe we should stick to the types timeval or timespec uses or even use the types C++11 uses in duration [Link](https://www.cplusplus.com/reference/chrono/duration/).
muellerr
commented
Hmmm.. it just makes it a bit mor explicit. I guess you mean for example time_t ? These typedefs were inteded to explicitely be used everywhere uint32_t is used to pass around millisecond values. The new C++ types are a bit more complicated but the clock library will become more powerful soon anyway. I started to play around with the chrono library. Hmmm.. it just makes it a bit mor explicit. I guess you mean for example time_t ?
These typedefs were inteded to explicitely be used everywhere uint32_t is used to pass around millisecond values.
The new C++ types are a bit more complicated but the clock library will become more powerful soon anyway. I started to play around with the chrono library.
Maybe continue using uint32_t for now?
muellerr
commented
instead of writing something like uint32_t lockTimeout, I could write millis_t lockTimeout for example instead of writing something like uint32_t lockTimeout, I could write millis_t lockTimeout for example
|
||||
typedef uint32_t dur_millis_t;
|
||||
typedef double dur_seconds_t;
|
||||
|
||||
class Clock {
|
||||
public:
|
||||
|
@ -13,12 +13,12 @@ void Stopwatch::start() {
|
||||
Clock::getClock_timeval(&startTime);
|
||||
}
|
||||
|
||||
millis_t Stopwatch::stop() {
|
||||
dur_millis_t Stopwatch::stop() {
|
||||
stopInternal();
|
||||
return elapsedTime.tv_sec * 1000 + elapsedTime.tv_usec / 1000;
|
||||
}
|
||||
|
||||
seconds_t Stopwatch::stopSeconds() {
|
||||
dur_seconds_t Stopwatch::stopSeconds() {
|
||||
stopInternal();
|
||||
return timevalOperations::toDouble(elapsedTime);
|
||||
}
|
||||
|
@ -40,12 +40,12 @@ public:
|
||||
* Calculates the elapsed time since start and returns it
|
||||
* @return elapsed time in milliseconds (rounded)
|
||||
*/
|
||||
millis_t stop();
|
||||
dur_millis_t stop();
|
||||
/**
|
||||
* Calculates the elapsed time since start and returns it
|
||||
* @return elapsed time in seconds (double precision)
|
||||
*/
|
||||
seconds_t stopSeconds();
|
||||
dur_seconds_t stopSeconds();
|
||||
|
||||
/**
|
||||
* Displays the elapsed times on the osstream, depending on internal display
|
||||
|
Where are does types used?
stopwatch. could also be used somewhere else, is more explicit in my opinion. maybe also use it instead of uint32_t for all milliseconds related stuff?
Hm I think we should stick with timeval and the types defined there. Someday this might be replaced by timespec and uint32_t will be to small anyway.