av手机免费在线观看,国产女人在线视频,国产xxxx免费,捆绑调教一二三区,97影院最新理论片,色之久久综合,国产精品日韩欧美一区二区三区

C語言

c++利用windows函數(shù)實現(xiàn)計時

時間:2025-05-04 17:39:38 C語言 我要投稿
  • 相關(guān)推薦

c++利用windows函數(shù)實現(xiàn)計時范例

  計時怎樣利用代碼實現(xiàn)呢?以下是為大家分享的c++利用windows函數(shù)實現(xiàn)計時范例,供大家參考借鑒,歡迎瀏覽!

  復(fù)制代碼 代碼如下:

  //Windows系統(tǒng)下可以用 time(),clock(),timeGetTime(),GetTickCount(),QueryPerformanceCounter()來對一段程序代碼進行計時

  #include

  #include

  #include//time_t time() clock_t clock()

  #include//timeGetTime()

  #pragma comment(lib, "Winmm.lib") //timeGetTime()

  //使用方法:將Sleep()函數(shù)換成需要測試運行時間的函數(shù)即可。

  int main()

  { //用time()來計時,以秒為單位

  time_t timeBegin, timeEnd;

  timeBegin = time(NULL);

  Sleep(1000);

  timeEnd = time(NULL);

  printf("%dn", timeEnd - timeBegin);

  //用clock()來計時,以毫秒為單位

  clock_t clockBegin, clockEnd;

  clockBegin = clock();

  Sleep(800);

  clockEnd = clock();

  printf("%dn", clockEnd - clockBegin);

  //用timeGetTime()來計時,以毫秒為單位

  DWORD dwBegin, dwEnd;

  dwBegin = timeGetTime();

  Sleep(800);

  dwEnd = timeGetTime();

  printf("%dn", dwEnd - dwBegin);

  //用GetTickCount()來計時,以毫秒為單位

  DWORD dwGTCBegin, dwGTCEnd;

  dwGTCBegin = GetTickCount();

  Sleep(800);

  dwGTCEnd = GetTickCount();

  printf("%dn", dwGTCEnd - dwGTCBegin);

  //用QueryPerformanceCounter()來計時,以微秒為單位

  LARGE_INTEGER large_interger;

  double dff;

  __int64 c1, c2;

  QueryPerformanceFrequency(&large_interger);

  dff = large_interger.QuadPart;

  QueryPerformanceCounter(&large_interger);

  c1 = large_interger.QuadPart;

  Sleep(800);

  QueryPerformanceCounter(&large_interger);

  c2 = large_interger.QuadPart;

  printf("本機高精度計時器頻率%lfn", dff);

  printf("第一次計時器值%I64dn第二次計時器值%I64dn計時器差%I64dn", c1, c2, c2 - c1);

  printf("計時%lf毫秒nn", (c2 - c1) * 1000 / dff);

  return 0;

  }

【c++利用windows函數(shù)實現(xiàn)計時】相關(guān)文章:

c和c++中實現(xiàn)函數(shù)回調(diào)的方法08-30

C++函數(shù)模板09-14

C++函數(shù)考點歸納09-30

c++函數(shù)指針使用示例07-26

C/C++函數(shù)調(diào)用的方式07-29

C++如何調(diào)用matlab函數(shù)06-29

C++函數(shù)指針學(xué)習(xí)教程10-01

C++中內(nèi)聯(lián)函數(shù)的應(yīng)用09-21

C++調(diào)用C函數(shù)的方法05-21