ホームに戻る
 時間測定

#include <stdio.h>
#include <time.h>

int main(){
  clock_t start, end;

  start = clock();

  getchar();

  end = clock();

  printf("\n\n%.2f秒かかりました\n", (double)((end-start)/CLOCKS_PER_SEC));

  return 0;
}

 Win32API を使った時間測定

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

void test_func(){
  for(int i = 0; i < 100000000; i++){

  }
}

int main(){
  LARGE_INTEGER freq, start, end;

  if(QueryPerformanceFrequency(&freq)){
    double unit = 1000;

    QueryPerformanceCounter(&start);
    test_func();
    QueryPerformanceCounter(&end);

    unit = unit / freq.QuadPart;

    printf("%lfms\n", (double)((end.QuadPart - start.QuadPart) * unit));
  }

  return 0;
}

inserted by FC2 system