Re: [問題] tic,toc在固定參數下執行得到的結果會갠…已回收
※ 引述《senga (N年第一次改暱稱..)》之銘言:
: 請教各位,
: 目前使用tic, toc分別針對兩支對照的子程式(A,B)記錄其時間
: 不過卻發現在同一組參數下,執行出來的時間每次都不一樣...
: 也就是說有時候A比較快,有時候B比較快
: 如:
: A B
: 0.015 0.031
: 0.015 0.015
: 0.030 0.016
: 0.020 0.040
: 結果我搞不清楚到底哪個好...
: 請問是有什麼原因可能會造成這樣的情況嗎
一定會有誤差的
所以就是多跑幾次看看
像是這樣
tic
for i = 1 : 1e50
執行A
end
toc
tic
for i = 1 : 1e50
執行B
end
toc
這樣子多跑幾次就比較能看出速度差異了
誤差問題也可以比較能忽略
--
Deserves death! I daresay he does. Many that live deserve death. And some die
that deserve life. Can you give that to them? Then be not too eager to deal out
death in the name of justice, fearing for your own safty. Even the wise cannot
see all ends.
Gandalf to Frodo
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.120.24.116
推
04/07 16:14, , 1F
04/07 16:14, 1F
推
04/08 04:38, , 2F
04/08 04:38, 2F