WindowsでC++コードの処理時間を高精度計測する

QueryPerformanceCounterを使う。

#include <stdio.h>
#include <windows.h>

int main(void)
{
  LONGLONG  freq, cnt0, cnt1;
  double time;

  if(!QueryPerformanceFrequency((LARGE_INTEGER *)&freq)){
    printf("no high-resolution counter.\n");
    exit(1);
  }
  QueryPerformanceCounter((LARGE_INTEGER *)&cnt0);
  // ここに計測したい処理を書く
  QueryPerformanceCounter((LARGE_INTEGER *)&cnt1);
  time = (double)(cnt1-cnt0) / (double)freq;

  return 0;
}