From 005cd3b630fcf0f3870f426a0db5e54400a59ef9 Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Mon, 3 Jul 2023 22:17:34 +0200 Subject: timer: add simple linux watchclock timer --- test/timer.cc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 test/timer.cc (limited to 'test/timer.cc') 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 +#include +#include + +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; +} -- cgit v1.2.3