linux - 在shell中获取程序执行时间

我想在几个不同的条件下在 linux shell 中执行一些东西,并且能够输出每次执行的执行时间。

我知道我可以编写一个 perl 或 python 脚本来执行此操作,但有没有办法可以在 shell 中执行此操作? (恰好是 bash)

最佳答案

使用内置的时间关键字:

$ help time

time: time [-p] PIPELINE
    Execute PIPELINE and print a summary of the real time, user CPU time,
    and system CPU time spent executing PIPELINE when it terminates.
    The return status is the return status of PIPELINE.  The `-p' option
    prints the timing summary in a slightly different format.  This uses
    the value of the TIMEFORMAT variable as the output format.

Example:

$ time sleep 2
real    0m2.009s
user    0m0.000s
sys     0m0.004s

https://stackoverflow.com/questions/385408/

相关文章:

linux - 更改 crontab 文件后重新启动 cron?

python - 如何检查变量是否是类?

python - 如何逐行读取大型文本文件,而不将它们加载到内存中?

linux - 使用sudo时如何保留环境变量

python - Python 是强类型的吗?

linux - 如何递归查找并列出具有子目录和时间的目录中的最新修改文件

python - 从 Numpy 数组 : How do I specify the index c

linux - 如何使用自定义分隔符将多行文件名合并为一个?

python - 在 Python 中获取临时目录的跨平台方法

python - Django:显示选择值