如何获取timestamp类型的精度到纳秒级

 我来答
金色潜鸟
2017-05-12 · TA获得超过3.2万个赞
知道大有可为答主
回答量:1.3万
采纳率:89%
帮助的人:5501万
展开全部
获取时间章,开始,停,测CPU速度 的 函数们如下。(MS VC++ 6.0 编译器。)
#define NOMINMAX
#include <windows.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
// "Read Time Stamp Counter".
__forceinline unsigned _int64 My_clock(void)
{
_asm _emit 0x0F
_asm _emit 0x31
}
unsigned _int64 Start(void) { return My_clock();}
unsigned _int64 Stop(unsigned _int64 m_start, unsigned _int64 m_overhead)
{return My_clock()-m_start - m_overhead; }
void get_CPU_speed()
{
unsigned _int64 m_start=0, m_overhead=0;
unsigned int CPUSpeedMHz;
m_start = My_clock();
m_overhead = My_clock() - m_start - m_overhead;
printf("overhead for calling My_clock=%I64d\n", m_overhead);
m_start = My_clock();
wait_ms(2000);
CPUSpeedMHz=(unsigned int) ( (My_clock()- m_start - m_overhead) / 2000000);
printf("CPU_Speed_MHz: %u\n",CPUSpeedMHz);
}
void wait ( int seconds )
{
clock_t endwait;
endwait = clock () + seconds * CLOCKS_PER_SEC ;
while (clock() < endwait) {}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式