在haskell中执行定时命令

apl*_*vin 1 io haskell timing

我有一段看起来像这样的代码:

start <- getCPUTime
(_, _, _, ph) <- createProcess (shell shellCmd) 
end <- (waitForProcess ph >> getCPUTime)
print start
print end
Run Code Online (Sandbox Code Playgroud)

如您所见,代码应该在执行之前和之后运行命令shellCmd和打印getCPUTime值.但是,它工作不正确:时间差总是零或15625000000(0.015秒).据我所知,原因是懒惰,但无法解决它.我在互联网上找到了一些例子(其中一个在上面),但没有一个能为我工作.

这样做的正确方法是什么,为什么?

Tho*_*son 5

我的第一个想法是你的shell命令非常快 - 甚至可能无效.然后我阅读了以下文档getCPUTime:

Computation getCPUTime returns the number of picoseconds
CPU time used by the current program
Run Code Online (Sandbox Code Playgroud)

因此,您分叉的过程不会计入您的CPU时间.也许你想通过挂钟时间getCurrentTimeData.Time