aboutsummaryrefslogblamecommitdiff
path: root/test/timer.cc
blob: 6bc783c4cd40240cdbeccb3c1638467cc719d2bb (plain) (tree)
1
2
3
4
5
6
7
8
9
10




                   
                 
 


                                                                              



                        
                             

                       
              


                        
                             

                       
              


           
#include <timer.h>
#include <unistd.h>
#include <cstdio>

int main() {
  timer::timer t;

  const auto kShowTime = [&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);
  }
  kShowTime();

  {
    puts("Sleep 500ms");
    timer::scoped_timer s{t};
    usleep(500 * 1000);
  }
  kShowTime();

  return 0;
}