Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*This gist only compare C way to get a timestamp clock_monotonic against C++11 way.*/
- #include <iostream>
- #include <time.h>
- #include <chrono>
- #include <ctime>
- void get_clock_time_us_time_h(unsigned long &val){
- struct timespec ts;
- clock_gettime(CLOCK_MONOTONIC, &ts);
- val = (ts.tv_sec * 1000000 + ts.tv_nsec / 1000);
- }
- void get_clock_time_us_std_time(unsigned long &val){
- val = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::steady_clock::now()).time_since_epoch().count();
- }
- int main(){
- unsigned long time = 0;
- get_clock_time_us_time_h(time);
- std::cout << time << std::endl;
- time = 0;
- get_clock_time_us_std_time(time);
- std::cout << time << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement