美文网首页
c++ 获取 毫秒级时间

c++ 获取 毫秒级时间

作者: 星星之火666 | 来源:发表于2019-04-24 14:20 被阅读0次
  • <timeb.h>
#include <iostream>
#include<sys/timeb.h>
using namespace std;

long long systemtime()
{
    timeb t;
    ftime(&t);
    return t.time*1000+t.millitm;
}

int main() 
{
    long long start=systemtime();
    
    int i=1000000000;
    while(i--);
    
    cout<<systemtime()-start<<" 毫秒";
    return 0;
}
// 结果:1801 毫秒
  • <windows.h>
#include<iostream>
#include<windows.h>
using namespace std;

int main()
{
    DWORD start = GetTickCount(); // 从操作系统启动所经过(elapsed/过去)的毫秒数,它的返回值是 DWORD
    Sleep(2019);
    cout << GetTickCount() - start << " 毫秒";
    return 0;
}

相关文章

网友评论

      本文标题:c++ 获取 毫秒级时间

      本文链接:https://www.haomeiwen.com/subject/rjqggqtx.html