[問題] 計算程式時間
要計算矩陣相乘的時間
用Stopwatch計算的話,它會因電腦狀況(cpu會去執行其它)不同執行時間會有小差異m
上網查到Process.GetCurrentProcess().TotalProcessorTime
用了之後,計算出的時間會固定(但會固定在4種值)
其中兩種是(15.6001和31.2002)剛好2倍,其他兩種值比較少出現。
我的疑問是,相同的兩個矩陣相乘,不管執行幾次,正常應該cpu使用時間是一定的吧?
還是我的觀念有錯呢?
感謝大家
以下是簡單測試的code (矩陣大小是 1x1024 X 1024x1024)
TimeSpan ts1 =
System.Diagnostics.Process.GetCurrentProcess().TotalProcessorTime;
for (int x = 0; x < 1024; x++)
{
double sum = 0;
for (int y = 0; y < 1024; y++)
{
sum = sum + (Oridata[0, y] * A[y, x]);
}
WLD[x] = Math.Round(sum) / Cmax / Math.Pow(2, 14);
}
double Msecs =
System.Diagnostics.Process.GetCurrentProcess().TotalProcessorTime.Subtract(ts1).TotalMilliseconds;
listBox1.Items.Add(Msecs);
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.255.66.7
※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1499868204.A.36D.html
推
07/12 22:34, , 1F
07/12 22:34, 1F
推
07/12 22:44, , 2F
07/12 22:44, 2F
→
07/12 22:48, , 3F
07/12 22:48, 3F
→
07/12 22:48, , 4F
07/12 22:48, 4F
→
07/12 22:55, , 5F
07/12 22:55, 5F
→
07/12 22:56, , 6F
07/12 22:56, 6F
→
07/12 22:57, , 7F
07/12 22:57, 7F
那請問一下,我用stopwatch去測時間是約 19-21 之間。依我的邏輯來說..
用TotalProcessorTime的時間應該要小於stopwatch測的時間。
所以TotalProcessorTime測出來15.6我覺得合理,但31.2這值我不知道怎麼解釋?
不知道有沒有合理的解釋呢? 謝謝。
※ 編輯: KYO5 (111.255.66.7), 07/13/2017 09:42:13
→
07/13 11:44, , 8F
07/13 11:44, 8F
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章