#include <windows.h>
#include <chrono>
#include <iostream>
#ifdef WIN32
LARGE_INTEGER litmp;
// 获取时钟频率
QueryPerformanceFrequency(&litmp);
LONGLONG freq = litmp.QuadPart;
// 当前时间
QueryPerformanceCounter(&litmp);
LONGLONG start = litmp.QuadPart;
#else
auto start = std::chrono::high_resolution_clock::now();
#endif
// TODO
#ifdef WIN32
// 当前时间
QueryPerformanceCounter(&litmp);
LONGLONG end = litmp.QuadPart;
// 计算时间差
double diff = (double)(end - start) / (double)(freq) * 1000;
std::cout << "send package time: [" << diff << "]ms";
#else
auto end = std::chrono::high_resolution_clock::now();
// 计算时间差
std::chrono::duration<double, std::ratio<1, 1000>> diff = end - start;
std::cout << "send package time: [" << diff.count() << "]ms";
#endif
时钟计时(Windows、C++11)
于 2021-07-09 16:44:08 首次发布