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