c++ - Linux and Windows millisecond time -


i want milliseconds time of system (i don't care if it's real time, want accurate possible). method it?

#ifdef win32 unsigned long long freq; unsigned long long get_ms_time() {     large_integer t;     queryperformancecounter(&t);     return t.quadpart / freq; } #else unsigned long long get_ms_time() {     struct timespec t;     clock_gettime(clock_monotonic, &t);     return t.tv_sec * 1000 + t.tv_nsec / 1000000; } #endif 

how can wrap value signed int? tried doing , negative values (on linux, don't know on windows):

~ start -2083002438 ~ 15 seconds after.. -2082987440 ~ 15 seconds after.. -2082972441 

i this. ~ start x ~ 15 seconds after.. x + 14998 ~ 15 seconds after.. x + 29997

where x positive number. (i want output positive , increasing)

i in code...

timespec specstart, specstop;  // start time ( unix timestamp ) in seconds... clock_gettime( clock_monotonic_raw, &starttime );  int starttimeint = starttime.tv_sec; std::cout << "start time : " << starttimeint << std::endl;  ... // stop time ( unix timestamp ) in seconds... clock_gettime( clock_monotonic_raw, &stoptime );  int stoptimeint = stoptime.tv_sec; std::cout << "stop time : " << stoptimeint << std::endl;  // time diff stop time start time unsigned long long timestart = specstart.tv_sec * 1000000000 + specstart.tv_nsec; unsigned long long timestop = specstop.tv_sec * 1000000000 + specstop.tv_nsec; unsigned long long timedelta = timestio - timestart; // time diff in nanoseconds.   int microsec = timedelate / 1000;  int msec = timedelta / 1000000; int sec = timedelta / 1000000000;  std::cout << "time diff : " << std::endl     << sec << " s" << std::endl     << msec << " ms" << std::endl     << microsec << " µs" << std::endl     << timedelta << " ns" << std::endl; 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -