Annotation of 43BSDTahoe/new/help/src/f77/timing, revision 1.1.1.1

1.1       root        1: .TI F77/TIMING "Sep. 15, 1984"
                      2: Timing Programs, Profiles
                      3: 
                      4: UNIX divides the processor time charged to a job into user time and
                      5: system time.  User time is the time the processor spends computing
                      6: for the process; system time is the time the processor spends 
                      7: executing system calls (I/O requests, forks, execs, etc.)
                      8: on your behalf.
                      9: 
                     10: Both kinds of time can vary according to the system load
                     11: because processor time spent handling interrupts is charged
                     12: to the current user even if the activity was caused by some
                     13: other user or some system function.
                     14: In practise the user time varies much less than the system time.
                     15: The times are kept in 60th of a second units.
                     16: You are charged for both user time and system time.
                     17: 
                     18: Program segments may be timed using the dtime() library subroutine
                     19: (see "man 3f dtime"):
                     20: 
                     21: .nf
                     22:              dimension tarray(2)
                     23:                 ...
                     24:              call dtime(tarray)
                     25:                ... program segment to be timed ...
                     26:              call dtime(tarray)
                     27:              print 8000, tarray
                     28:        8000  format(" user time = ",f8.3," system time = ",f8.3)
                     29: .fi
                     30: 
                     31: Dtime() in this example will put the user time used by the 
                     32: program segment in tarray(1) and the system time used in tarray(2).
                     33: 
                     34: It is best to exclude I/O operations from the segment being timed.
                     35: Since the times are kept in units of a 60th of a second and vary by
                     36: system load, do not try to time any computation that takes less than 10
                     37: or 20 seconds.  If the computation is fast, put it in a loop and
                     38: time 10 or 100 repetitions.
                     39: 
                     40: It is also possible to profile an entire program and find out
                     41: how often each subprogram was called and how much time it used.
                     42: First compile the program with the '-p' flag, run it and then
                     43: execute the prof utility to print out the profile:
                     44: 
                     45: .nf
                     46:        % f77 -p prog.f
                     47:        prog.f:
                     48:           MAIN:
                     49:           sub1:
                     50:           sub2:
                     51:           sub3:
                     52:        Loading a.out ...
                     53:        % 
                     54:        % a.out
                     55:            ... program output ...
                     56:        % prof
                     57:        
                     58:                %time   cumsecs #call   ms/call name
                     59:                 41.1    3.37     2     1683.48 _sub1_
                     60:                 34.2    6.17     1     2800.24 _sub2_
                     61:                 12.2    7.17     1     1000.09 _MAIN__
                     62:                 11.8    8.13     2      483.37 _sub3_
                     63:                  0.4    8.17                   _fstat
                     64:                  0.2    8.18                   _x_putc
                     65: .fi
                     66: 
                     67: In this example, sub1 was called twice and used 3.37 seconds of processor
                     68: time (41% of the total), sub2 was called once and used 
                     69: 6.17 - 3.37 = 2.80 seconds (34%), etc.  Prof keeps track of the sum
                     70: of user and system times.  The last two lines of the output are for 
                     71: library routines which were not compiled with the profile option.
                     72: 
                     73: For more extensive profiling statistics, use the '-pg' option and the
                     74: gprof command.  See "man f77" and "man gprof" for details.
                     75: 
                     76: It is also possible to time entire commands.  You can do it directly
                     77: by invoking the C Shell's builtin time command:
                     78: 
                     79: .nf
                     80:        % time a.out
                     81:        6.5u 4.6s 0:23 48% 12+47k 690+688io 17pf+0w
                     82: .fi
                     83: 
                     84: This is partially documented in "man csh" and more fully in "An
                     85: Introduction to the C shell", section 2.8.  It tells us the command
                     86: used 6.5 seconds of user time, 4.6 seconds of system time and took 23
                     87: seconds of real (clock) time to finish.  During those 23 seconds, it
                     88: used 48% of the cpu cycles( 48% = (6.5+4.6)/23. ).  On the average, it
                     89: used 12k bytes of program space and 47k bytes of data space.  The
                     90: program did 690 disk reads and 688 disk writes, had 17 page faults and
                     91: did not have any pages swapped out.
                     92: 
                     93: A second method for timing a program is to use /bin/time:
                     94: 
                     95: .nf
                     96:        % /bin/time  a.out
                     97:               46.0 real         5.5 user         3.8 sys  
                     98: .fi
                     99: 
                    100: It is similar to the C shell time, but gives much less information.
                    101: Note that both commands are named time.  If you type "man time",
                    102: you will be told about /bin/time rather than the command built
                    103: into the C shell.
                    104: 
                    105: A third way is to set the C shell variable "time" to a minimum.
                    106: Thereafter, if a command takes more than that amount of cpu time
                    107: (system plus user time),
                    108: the statistics will automatically be listed using the same format as
                    109: the C shell time command.  This is reversed by the unset time command.
                    110: 
                    111: .nf
                    112:        % set time = 4
                    113:        % a.out
                    114:        5.7u 4.3s 0:59 16% 12+47k 703+654io 4pf+0w
                    115:        % 
                    116:        % unset time
                    117:        % a.out
                    118:        %

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.