http://hi.baidu.com/ronyo/blog/item/ee7e71cf7d46c338f8dc61ad
例子:
#include<iostream> using namespace std; /////////// #ifndef __MyTimer_H__ #define __MyTimer_H__ #include <windows.h> class MyTimer{ private: int _freq; LARGE_INTEGER _begin; LARGE_INTEGER _end; public: long costTime; // 花费的时间(精确到微秒) public: MyTimer(){ LARGE_INTEGER tmp; QueryPerformanceFrequency(&tmp); _freq = tmp.QuadPart; costTime = 0; } void Start(){ // 开始计时 QueryPerformanceCounter(&_begin); } void End(){ // 结束计时 QueryPerformanceCounter(&_end); costTime = (long)((_end.QuadPart - _begin.QuadPart) * 1000000 / _freq); } void Reset(){ // 计时清0 costTime = 0; } }; #endif ///////////////// int main(){ MyTimer mt; mt.Start(); int i; int sum=0; for(i=0;i<12345678;i++){ sum=sum+i; } mt.End(); cout<<"Total cost time:"<<mt.costTime<< " us" << endl; return 0; }
原文链接: https://www.cnblogs.com/gongpixin/p/4477388.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/149555
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!