Section 4.16. Timing Execution: time


[Page 151 (continued)]

4.16. Timing Execution: time

It is sometimes useful to know how long it takes to run a specific command or program (or more to the point, to know how long it takes relative to how long something else takes) (Figure 4-32).

Figure 4-32. Description of the time command.

Utility: time [-p] command-line

The time command can be used to report the execution time of any Linux command specified by command-line. Time is reported in both elapsed time and CPU time (CPU time is expressed as two values, user time and system time). When the -p option is used, time reports in the traditional UNIX format.


For example:

$ time -p sort allnames.txt >sortednames.txt real    0m 4.18s user    0m 1.85s sys     0m 0.14s $ _ 


This command tells us it took over 4 seconds of "wall clock" time to sort our file. But the total CPU time used was 1.99 seconds (user time plus system time).

The time command is particularly useful when testing programs or scripts on small amounts of data where you can't "feel" the difference in the time required because they run so fast, but you know that when you run on your large amount of "real data," you'll want your program to be as efficient as possible.




Linux for Programmers and Users
Linux for Programmers and Users
ISBN: 0131857487
EAN: 2147483647
Year: 2007
Pages: 339

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net