Friday, September 02, 2005

Average Command Runtimes with runtime

39.4 Average Command Runtimes with runtime
The time command (39.2) will time a single run of a command - but the
results can vary from run to run. The runtime script runs a command
the number of times you specify, then averages the results. For

% runtime -5 getdata 0.5 outfile
...wait a while...
runtime summary - 5 runs of
% getdata 0.5 outfile
(working directory = /users/jerry/.src/getdata)

First run started at: Thu Mar 19 09:33:58 EST 1992
Last run finished at: Thu Mar 19 09:36:41 EST 1992

1 1.0u 7.4s 1:06 12% 0+108k 0+0io 0pf+0w
2 0.2u 0.8s 0:05 16% 0+128k 0+0io 0pf+0w
3 0.2u 1.3s 0:11 13% 0+116k 0+0io 0pf+0w
4 0.4u 2.7s 0:25 12% 0+108k 0+0io 0pf+0w
5 0.9u 5.9s 0:53 12% 0+108k 0+0io 0pf+0w

0.54u 3.62s 0:32 0+113k 0+0io 0pf+0w

It's good for testing different versions of a program to find the
fastest (or slowest!). If you're writing a program that will run a
lot, shaving 10% or 20% off its time can be worth the work.

Note that the command you run can't have any redirection in it; that's
because runtime does some redirection of its own. You can redirect the
output of runtime into a log file though, and run the whole mess in
the background. For example:

% runtime -5 getdata 0.5 outfile > runtime.out &
[1] 12233

The summary will go to the runtime.out file.


Post a Comment

<< Home