CPU 时间怎么会低于 GHC 的 RTS 统计数据中的挂钟时间?

How can the CPU time be lower than wall-clock time on GHC's RTS stats?

我有一个程序与 -rtsopts 链接并用 +RTS -s 调用,我得到这个时间:

  INIT    time    0.000s  (  0.001s elapsed)
  MUT     time    4.047s  (  9.694s elapsed)
  GC      time    0.578s  (  0.514s elapsed)
  RP      time    0.000s  (  0.000s elapsed)
  PROF    time    0.000s  (  0.004s elapsed)
  EXIT    time    0.000s  (  0.000s elapsed)
  Total   time    4.625s  ( 10.209s elapsed)

这个程序 运行 大约 10 秒。 它与线程 RTS 链接,但它使用 -N1,所以我不明白为什么挂钟时间和 CPU 时间之间首先会有差异。

我刚刚在 GHC 用户指南中找到了这个:

Next there is the CPU time and wall clock time elapsed broken down by what the runtime system was doing at the time.

那么,CPU 时间低于挂钟时间有何意义?

注意:我的计算机在我的程序执行期间没有做任何艰苦的工作,当然没有那么多..这就是为什么我很困惑并担心我的程序运行不正常。

更新:我想我可能找到了罪魁祸首:RTS 是否计算了 IO 的 cpu 时间?如果不是,那可能就是原因,有大量写入。

挂钟时间包括等待网络、磁盘、用户输入等所花费的时间,而 CPU 时间仅包括在(恰好)一个 CPU 上积极计算某事所花费的时间。 (当计算多个 CPU 时,每个花费的时间加在一起。)