//C++中高精度时间差计算
#include <math.h>
#ifdef WIN32
#include <windows.h>
#else
#include <unistd.h>
#include <sys/time.h>
#endif // WIN32
using namespace std;
double get_current_time_ms()
{
#ifdef WIN32
LARGE_INTEGER freq;
LARGE_INTEGER pc;
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&pc);
return pc.QuadPart * 1000.0 / freq.QuadPart;
#else
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000.0 + tv.tv_usec * 0.001;
#endif // WIN32
}
int main()
{
double star_time = get_current_time_ms();
Sleep(100);
printf("predict time: %lf", get_current_time_ms() - star_time);
}
C++程序高精度时间计算方法并将double转字符串
最新推荐文章于 2024-05-04 15:29:43 发布