3
我想測量一下Haskell用來執行一些函數和使用TimeIt軟件包的時間(我也試過these建議)。但是顯示的時間從實際花費的時間應用不同(我已經跑了+ RTS -sstderr選擇應用程序):爲什麼Haskell函數執行時間測量不同於ghc時序?
CPU time: 4.85s
...
INIT time 0.00s ( 0.00s elapsed)
MUT time 0.98s (61.69s elapsed)
GC time 0.22s ( 0.19s elapsed)
EXIT time 0.00s ( 0.00s elapsed)
Total time 1.20s (61.89s elapsed)
應用來源:
import qualified Data.ByteString.Lazy.Char8 as LBS
import System.Environment
import Data.Char
import Data.Int
import System.TimeIt
readChunks :: Int64 -> LBS.ByteString -> Int64
readChunks size str
| LBS.null str = 0
| otherwise = let (chunk, rest) = LBS.splitAt size str
in do
let len = LBS.length chunk
len `seq` len + readChunks size rest
processFile :: String -> IO()
processFile name = do
putStrLn name
content <- LBS.readFile name
let
(recNumStr, rest) = LBS.span (not.isControl) content
recNum = LBS.readInt recNumStr
case recNum of
Nothing -> putStrLn "can't parse"
Just (value, rest) -> print (value)
let chunkSize = 100*1024*1024
timeIt $ print (readChunks chunkSize rest)
更新:我發現Chronograph包顯示正確的執行時間(信息摘自此question)。
我試過沒有這部分的代碼,但時間沒有改變,我想,因爲第一行的長度很小。用ghc或外部計時器測量的時間也與輸入文件的大小有線性相關性。 – KolKir