VC获取高精度时间的例子

2014-10-31 22:15:08 · 作者: · 浏览: 70

  #include


  #include "KTimer.h"


  main()


  {


  unsigned t;


  KTimer timer;


  timer.Start();


  Sleep(1000);


  t = timer.Stop();


  printf("Lasting Time: %d\n",t);


  }


  //Timer2.cpp 使用了timeGetTime函数


  //需包含 ,但由于Windows头文件错综复杂的关系


  //简单包含 比较偷懒:)


  //编译行:CL timer2.cpp /link winmm.lib


  #include


  #include


  main()


  {


  DWORD t1, t2;


  t1 = timeGetTime();


  Sleep(1000);


  t2 = timeGetTime();


  printf("Begin Time: %u\n", t1);


  printf("End Time: %u\n", t2);


  printf("Lasting Time: %u\n",(t2-t1));


  }