1
我正在执行ssh命令readProcess
(来自System.Process
包),我想花时间执行多长时间并将其与print命令输出。寻找一个简单的方法来计时执行readProcess(没有标准)
我知道可以根据标准准确计时,但标准似乎花时间进行大量设置和拆卸以及打印额外的输出。我不打算运行完整的基准测试,只是显示ssh命令运行需要多长时间。
到目前为止,我已经尝试了System.TimeIt
包,但结果不正确。例如,这应报告至少5秒(只是运行sleep 5
):
>>> timeIt $ readProcess "sleep" ["5"] []
CPU time: 0.04s
这里是System.TimeIt
是引擎盖下做:
-- |Wrap an 'IO' computation so that it prints out the execution time.
timeIt :: IO a -> IO a
timeIt ioa = do
(t, a) <- timeItT ioa
printf "CPU time: %6.2fs\n" t
return a
-- |Wrap an 'IO' computation so that it returns execution time is seconds as well as the real value.
timeItT :: IO a -> IO (Double, a)
timeItT ioa = do
t1 <- getCPUTime
a <- ioa
t2 <- getCPUTime
let t :: Double
t = fromIntegral (t2-t1) * 1e-12
return (t, a)
这看起来非常简单就够了,但我不明白出来一种方法来强制执行a <- ioa
。用!
注释似乎没有区别。
谢谢!
谢谢!这就说得通了。 '''getCurrentTime'''给出了期望的结果。 – jhickner