use time command as a simple benchmark tool

October 20th, 2007 mysurface Posted in Calculation, time | Hits: 92893 | 13 Comments »

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 and You can do this

time ./

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

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

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

13 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:

  7. hey, can someone tell me how to copy the result of the time function to a file? I intend to run a program inside the script 100000 times and i need to copy the output of the time function inside the script to a file..

  8. Thanks for the simple solution :)

    time > output 2> err.log

    You can also drop 2> err.log to have errors on stderr(usually sent to stdout) instead

  9. I added the following alias to my .bashrc

    alias casio=’/usr/bin/time -f “\n%E elapsed,\n%U user,\n%S system,\n%M memory\n%x status”‘

    so now i just

    # casio ls -alhF /opt/somefolder

    and I get the time the process took to run

  10. I had to test my Perl script’s execution time, I could have used NYTProf but then someone on IRC suggested me to use “time perl”. Worked like a charm. Awesome utility!

  11. cartierlovejesduas I visited several websites but the audio quality for audio songs present at tthis site is in fact marvelous.
    bagues cartier or blanc faux

  12. cartierlovejesduas The New Testament is a fulfilment of the Old Testament. Both are critical to understanding. There was a sacrificial system put into place that was fulfilled by Christ’s sacrifice. Check it out before you judge it.
    cartier love bangle size 16 price

  13. cartierlovejesduas That looks like one yummy bowl of soup. I love using the fresh peppers from our garden in everything. They are so much tastier! I haven’t heard of Gold n Plump Chicken before. Could it be because it’s not distributed in the northeast?
    clover necklace van cleef fake

Leave a Reply