获取程序的执行时间在外壳

编程入门 行业动态 更新时间:2024-10-12 10:26:00
本文介绍了获取程序的执行时间在外壳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想了几个不同的条件下执行在Linux Shell中的东西,并且能够输出每个执行的执行时间。

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.

我知道我可以写一个Perl或Python脚本,将做到这一点,但有一个方法可以让我做的壳呢? (这恰好是bash)的

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)

推荐答案

使用内建的时间命令:

$ 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. times: times Print the accumulated user and system times for processes run from the shell.

例如:

$ time sleep 2

real 0m2.009s user 0m0.000s sys 0m0.004s

更多推荐

获取程序的执行时间在外壳

本文发布于:2023-11-24 06:04:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1624180.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:执行时间   外壳   程序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!