我想在几个不同的条件下在 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/