Live Chat!

use time command as a simple benchmark tool

1 votos Vota!!

October 20th, 2007 mysurface Posted in Calculation, time | Hits: 20355 |

Sometimes you need to track execution time for some apps for benchmarking, time command is a handy tool. Let say you have wrote few scripts trying to grep some info from some log files, each of the scripts uses different techniques or command combos. You can run your scripts along with time command, and compare their’s execution time.

Let’s assume you have written two script name script1.sh and script2.sh. You can do this

time ./script1.sh

Same thing to script2.sh, and the results will looks as bellow:

real    0m1.005s
user    0m0.000s
sys     0m0.008s

real shows you the execution time script1.sh takes, o minutes 1.005 seconds. user and sys tracks the CPU processing time. From the results, shows us that script1.sh uses 8 milliseconds CPU processing time in kernel mode (sys) and None in user mode.

6 Responses to “use time command as a simple benchmark tool”

  1. Wow — that’s exactly what I needed. I wish I had a good, long script I could use it with, though. :(

  2. Thanks!

    So simple but so useful

  3. Excellent!!!

    Elegant as always, i love Linux :)

  4. Useful, thanks!

  5. I have a simple short script for test. (cursor)
    The only output I can get is:

    {$}[4] time ./cursor
    0.005u 0.062s 0:06.85 0.8% 0+0k 0+0io 0pf+0w

    If I try: time -f ./cursor or any other switch I get:
    -f: Command not found.

    even if I try time -V or –version it’s still: command not found… ???

  6. I had the same problem.

    try it with /usr/bin/time.

    I found the solution at:
    http://www.oreillynet.com/linux/cmd/cmd.csp?path=t/time

Leave a Reply

Security Code: