我想在linux shell中在几种不同的条件下执行一些东西,并且能够输出每次执行的执行时间.
我知道我可以编写一个perl或python脚本来实现这一点,但是有没有一种方法可以在shell中实现呢?(恰巧是bash)
我想在linux shell中在几种不同的条件下执行一些东西,并且能够输出每次执行的执行时间.
我知道我可以编写一个perl或python脚本来实现这一点,但是有没有一种方法可以在shell中实现呢?(恰巧是bash)
使用内置的time
关键字:
$ 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.
例子:
$ time sleep 2
real 0m2.009s user 0m0.000s sys 0m0.004s