我正在运行一个执行长计算的Haskell程序.经过一些分析和追踪,我注意到以下几点:
$ /usr/bin/time -v ./hl test.hl
9000045000050000
Command being timed: "./hl test.hl +RTS"
User time (seconds): 1.43
System time (seconds): 1.15
Run Code Online (Sandbox Code Playgroud)
它使用了大量的系统时间,即使我的代码没有显式调用任何系统调用(它读取文件并解释其中的一些代码).
使用strace -ttT运行它会显示很多对计时器的调用:
17:04:52.454513 clock_gettime(CLOCK_THREAD_CPUTIME_ID, {1, 282721271}) = 0 <0.000529>
17:04:52.456223 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 <0.000720>
17:04:52.458749 rt_sigprocmask(SIG_BLOCK, [INT], [], 8) = 0 <0.000239>
17:04:52.460288 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, {1, 285126436}) = 0 <0.000255>
17:04:52.461650 --- SIGVTALRM {si_signo=SIGVTALRM, si_code=SI_TIMER, si_pid=0, si_uid=0, si_value=0} ---
17:04:52.462242 rt_sigreturn() = 0 <0.000458>
Run Code Online (Sandbox Code Playgroud)
我以为它可能是RTS时钟,所以我禁用它并重新运行:
$ /usr/bin/time -v ./hl test.hl +RTS -V0
9000045000050000
Command …Run Code Online (Sandbox Code Playgroud)