What time is it?

Recently, I was writing judge system for my high school for algorithms competitions. Because of short deadline and other activities, I was coding it in a hurry. During this project I experienced strange behavior of linux command “time“.

I knew that “time” can measure time as well as memory used, so I look into manual to see how I could accomplish that. Man said that I need to use -f option. So I typed:
[code lang="bash"]
time -f "%M %e" ./program
[/code]
and get:
[code lang="bash"]
bash: -f: command not found
[/code]
After working out for a while I noticed that there are two types of “time“. A bash built-in and a standalone version. Option “-f” features in standalone version. Although “which” points to standalone version, the default command is built-in. To use more sophisticated “time” program, it is needed to give full path. Such as:
[code lang="bash"]
/usr/bin/time -f "%M %e" ./program
[/code]

To change default version to standalone GNU time I used alias:
[code lang="bash"]
alias time="/usr/bin/time"
[/code]

Sometimes a little of thinking is required to solve strange problems. However that doesn’t change the fact that current state of “time” behavior is weird.

  1. Pasci2007-02-07 22:32

    Many thanks,
    Just solved my problem.. :D

    Regards Pasci

Leave a Comment

authimage