开发者

Issues measuring program execution time in Linux/Bash

Hopefully not a dupe of this question...

I'm trying to determine the curve of a specified program's runtime with the time function.

What I would like to do is automate this process to get several hundred points of data to graph in Excel, however I am getting different output when running in a Linux terminal vs a bash script.

Here is what I get when I run it fr开发者_Go百科om the terminal:

time program_1 500
> 0.004u 0.000s 0:00.00 0.0%   0+0k 0+0io 0pf+0w

and here is my bash script (first argument is the program, second is the number)

#!/bin/bash

time $1 $2

and here...my output is different, even though when I echo the above statement in a literal manner, it appears to be the exact same call.

> sh runner.sh program_1 500
> 0.00user 0.00system 0:00.00elapsed 400%CPU (0avgtext+0avgdata 3488maxresident)k0inputs+0outputs (0major+275minor)pagefaults 0swaps

Why the difference?


Well, there are actually 2 time commands, and one of them is built into bash. man bash for the one installed in /usr/bin/time and help time for the builtin. Use the absolute path in your script to get same behaviour.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜