Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt methods to enable full range absolute time for timer object #241

Open
lefebvresam opened this issue Feb 6, 2024 · 1 comment
Open

Comments

@lefebvresam
Copy link

lefebvresam commented Feb 6, 2024

In timer.h some methods are defined to return the absolute time for a timer object. Some of them are depreciated becasue they do not return a data type within the full range:

Note: INFO macro expands to a printf

Timer int_t;
int_t.start();

INFO("Timer: %u ms", int_t.read_ms()); // depreciated
// is implemented as:
INFO("Timer: %u ms", std::chrono::duration_cast<std::chrono::duration<int, std::milli>>(int_t.elapsed_time()).count()); // depreciated

As decribed in time.h there are better options, but not yet incorporated in the code:

INFO("Timer: %llu ms", std::chrono::duration_cast<std::chrono::milliseconds>(int_t.elapsed_time()).count()); // 64bit value
INFO("Timer: %llu us", static_cast<long long int>(int_t.elapsed_time().count())); //64bit value
2^64  
1,84467E+19 us
1,84467E+16 ms
1,84467E+13 s
3,07446E+11 min
5124095576 h
213503982,3 d
584554,531 y
@multiplemonomials
Copy link
Collaborator

You're right, I think that this should be changed to use a 64 bit type. std::chrono::duration_cast<std::chrono::milliseconds>(int_t.elapsed_time()).count() is the correct std::chrono way to do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants