我在 Linux 中使用时间命令运行一个 jar 文件。下面是执行后的输出。
15454.58s real 123464.61s user 6455.55s system
下面是执行的命令。
time java -jar -Xmx7168m Batch.jar
但执行该过程实际花费的时间是 9270 秒。
为什么实际时间(挂钟时间)和实际时间不同?
谁能解释一下?它在多核机器(32 核)上运行。
最佳答案
也许这可以解释您遇到的偏差。来自时间
Wikipedia article :
Because a program may fork children whose CPU times (both user and sys) are added to the values reported by the time command, but on a multicore system these tasks are run in parallel, the total CPU time may be greater than the real time.
除此之外,你对实时的理解符合time(7)
中给出的定义:
Real time is defined as time measured from some fixed point, either from a standard point in the past (see the description of the Epoch and calendar time below), or from some point (e.g., the start) in the life of a process (elapsed time).
另请参阅 bash(1)
(尽管其关于 time
命令的文档并不太全面)。
如果秒数对您来说足够精确,这个小包装器可以提供帮助:
#!/bin/bash
starttime=$( date +"%s" )
# run your program here
endtime=$( date +"%s" )
duration=$(( endtime-starttime ))
echo "Execution took ${duration} s."
注意:如果在程序运行时更改系统时间,结果将不正确。
关于Linux 时间命令——真实 vs 用户 vs 系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29121668/