fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <windows.h>
  4. #include <math.h>
  5. #define num 20
  6. #define cyc 1000000000ul
  7. using namespace std;
  8. int main(){
  9. LARGE_INTEGER startTime, endTime, fre;
  10. double times[num], timeAvg, timeSd;
  11. unsigned int i;
  12. int n;
  13. int p=1234;
  14. int q;
  15. QueryPerformanceFrequency(&fre); //取得CPU頻率
  16. printf("執行%3d輪,每輪執行 %d次\n\n", num, cyc);
  17. for (n = 0; n < num; n++){
  18. QueryPerformanceCounter(&startTime); //取得開機到現在經過幾個CPU Cycle
  19. for(i = 0; i < cyc; i++){
  20. //↓輸入測試程式↓
  21. q = p*2;
  22. //↑輸入測試程式↑
  23. }
  24. QueryPerformanceCounter(&endTime); //取得開機到程式執行完成經過幾個CPU Cycle
  25. times[n] = ((double)endTime.QuadPart - (double)startTime.QuadPart)/fre.QuadPart;
  26. }
  27. timeAvg = 0;
  28. timeSd = 0;
  29. for (n = 0; n < num; n++){
  30. timeAvg += times[n];
  31. printf("第%3d輪所需時間%15.10f秒\n", n + 1, times[n]);
  32. }
  33. timeAvg /= num;
  34. for (n = 0; n < num; n++){
  35. timeSd += (times[n] - timeAvg)*(times[n] - timeAvg);
  36. }
  37. timeSd = sqrt(timeSd / num);
  38. printf("\n執行完畢,\n平均執行時間%15.10f秒,\n標準差%15.10f秒\n", timeAvg, timeSd);
  39. system("pause");
  40. return 0;
  41. }
  42.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:21: fatal error: windows.h: No such file or directory
compilation terminated.
stdout
Standard output is empty