Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. /*This gist only compare C way to get a timestamp clock_monotonic against C++11 way.*/
  2.  
  3. #include <iostream>
  4. #include <time.h>
  5. #include <chrono>
  6. #include <ctime>
  7.  
  8. void get_clock_time_us_time_h(unsigned long &val){
  9. struct timespec ts;
  10. clock_gettime(CLOCK_MONOTONIC, &ts);
  11. val = (ts.tv_sec * 1000000 + ts.tv_nsec / 1000);
  12. }
  13.  
  14. void get_clock_time_us_std_time(unsigned long &val){
  15. val = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::steady_clock::now()).time_since_epoch().count();
  16. }
  17.  
  18. int main(){
  19. unsigned long time = 0;
  20. get_clock_time_us_time_h(time);
  21. std::cout << time << std::endl;
  22.  
  23. time = 0;
  24.  
  25. get_clock_time_us_std_time(time);
  26. std::cout << time << std::endl;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement