1

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

start <- getCPUTime
(_, _, _, ph) <- createProcess (shell shellCmd) 
end <- (waitForProcess ph >> getCPUTime)
print start
print end

如您所见,代码应该在执行之前和之后运行命令shellCmd并打印getCPUTime值。但是,它工作不正确:时间差始终为零或15625000000(0.015 秒)。据我了解,原因是懒惰,但不知道如何解决。我在 Internet 上找到了一些示例(其中一个在上面),但没有一个对我有用。

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

4

1 回答 1

5

我的第一个想法是你的 shell 命令真的很快——甚至可能是无效的。然后我阅读了以下文档getCPUTime

Computation getCPUTime returns the number of picoseconds
CPU time used by the current program

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

于 2012-09-05T16:05:48.417 回答