在shell中获取程序执行时间 [英] Get program execution time in the shell

查看:68
本文介绍了在shell中获取程序执行时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我知道我可以编写一个 perl 或 python 脚本来做到这一点,但是有没有办法在 shell 中做到这一点?(恰好是 bash)

解决方案

使用内置的time关键字:

<前>$帮助时间时间:时间 [-p] 管道执行 PIPELINE 并打印实时摘要、用户 CPU 时间、PIPELINE 终止时执行 PIPELINE 所花费的系统 CPU 时间.返回状态为PIPELINE的返回状态.`-p' 选项以稍微不同的格式打印计时摘要.这使用TIMEFORMAT 变量的值作为输出格式.

示例:

$ time sleep 2

<前>真实 0m2.009s用户 0m0.000s系统 0m0.004s

I want to execute something in a linux shell under a few different conditions, and be able to output the execution time of each execution.

I know I could write a perl or python script that would do this, but is there a way I can do it in the shell? (which happens to be bash)

解决方案

Use the built-in time keyword:

$ 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

这篇关于在shell中获取程序执行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆