diff options
author | Johannes Stoelp <johannes.stoelp@gmail.com> | 2023-07-03 22:17:34 +0200 |
---|---|---|
committer | Johannes Stoelp <johannes.stoelp@gmail.com> | 2023-07-03 22:17:34 +0200 |
commit | 005cd3b630fcf0f3870f426a0db5e54400a59ef9 (patch) | |
tree | 76bc9add7aa46a7ac61c072e5f1fe1b0d1551a01 /test/timer.cc | |
parent | 6b062584e56fe395be723220324ea384bf447971 (diff) | |
download | cpp-utils-005cd3b630fcf0f3870f426a0db5e54400a59ef9.tar.gz cpp-utils-005cd3b630fcf0f3870f426a0db5e54400a59ef9.zip |
timer: add simple linux watchclock timer
Diffstat (limited to 'test/timer.cc')
-rw-r--r-- | test/timer.cc | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/timer.cc b/test/timer.cc new file mode 100644 index 0000000..078c4bb --- /dev/null +++ b/test/timer.cc @@ -0,0 +1,28 @@ +#include <timer.h> +#include <unistd.h> +#include <cstdio> + +int main() { + timer::timer T; + + const auto show_time = [&T]() { + std::fprintf(stderr, "usec=%f msec=%f sec=%f\n", T.as_usec(), T.as_msec(), + T.as_sec()); + }; + + { + puts("Sleep 100ms"); + timer::scoped_timer s{T}; + usleep(100 * 1000); + } + show_time(); + + { + puts("Sleep 500ms"); + timer::scoped_timer s{T}; + usleep(500 * 1000); + } + show_time(); + + return 0; +} |