[問題] 測量執行時間

看板C_and_CPP作者 (City*Mate)時間14年前 (2009/11/29 09:29), 編輯推噓0(003)
留言3則, 3人參與, 最新討論串1/3 (看更多)
我想測量一個程式所執行的時間,不過似乎精密度非常的不夠 開發平台: Dev-C++ 我的作法如下,可是這樣子只能測到秒而已 有時低於一秒就變 0 了 #include <stdio.h> #include <stdlib.h> #include <time.h> double ta,tb; //ta記錄開始 tb記錄結束 double T; //T記錄時間差 int main (void) { ta=time(0); for (i=0;i<10000;i++) { do somthing } ta=time(0) T=ta-tb; printf("%lf",T) system("pause"); return 0; } -- http://www.wretch.cc/blog/jesse78131 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.113.249.122

11/29 09:44, , 1F
time.h 的 clock() 還不錯 ...
11/29 09:44, 1F

11/29 15:06, , 2F
打成tb?
11/29 15:06, 2F

11/29 16:07, , 3F
那是打錯了 不過還是不夠精確
11/29 16:07, 3F
文章代碼(AID): #1B4SvYVG (C_and_CPP)
文章代碼(AID): #1B4SvYVG (C_and_CPP)