Debian Codegraph @

doc/timerate.n

raw
1 '\"
2 '\" Copyright (c) 2005 Sergey Brester aka sebres.
3 '\"
4 '\" See the file "license.terms" for information on usage and redistribution
5 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6 '\"
7 .TH timerate n "" Tcl "Tcl Built-In Commands"
8 .so man.macros
9 .BS
10 '\" Note: do not modify the .SH NAME line immediately below!
11 .SH NAME
12 timerate \- Calibrated performance measurements of script execution time
13 .SH SYNOPSIS
14 \fBtimerate \fIscript\fR ?\fItime\fR? ?\fImax-count\fR?
15 .sp
16 \fBtimerate \fR?\fB\-direct\fR? ?\fB\-overhead\fI double\fR? \fIscript\fR ?\fItime\fR? ?\fImax-count\fR?
17 .sp
18 \fBtimerate \fR?\fB\-calibrate\fR? ?\fB\-direct\fR? \fIscript\fR ?\fItime\fR? ?\fImax-count\fR?
19 .BE
20 .SH DESCRIPTION
21 .PP
22 The \fBtimerate\fR command does calibrated performance measurement of a Tcl
23 command or script, \fIscript\fR. The \fIscript\fR should be written so that it
24 can be executed multiple times during the performance measurement process.
25 Time is measured in elapsed time using the finest timer resolution as possible,
26 not CPU time; if \fIscript\fR interacts with the OS, the cost of that
27 interaction is included.
28 This command may be used to provide information as to how well a script or
29 Tcl command is performing, and can help determine bottlenecks and fine-tune
30 application performance.
31 .PP
32 The first and second form will evaluate \fIscript\fR until the interval
33 \fItime\fR given in milliseconds elapses, or for 1000 milliseconds (1 second)
34 if \fItime\fR is not specified.
35 .sp
36 The parameter \fImax-count\fR could additionally impose a further restriction
37 by the maximal number of iterations to evaluate the script.
38 If \fImax-count\fR is specified, the evalution will stop either this count of
39 iterations is reached or the time is exceeded.
40 .sp
41 It will then return a canonical tcl-list of the form:
42 .PP
43 .CS
44 \fB0.095977 \(mcs/# 52095836 # 10419167 #/sec 5000.000 net-ms\fR
45 .CE
46 .PP
47 which indicates:
48 .IP \(bu 3
49 the average amount of time required per iteration, in microseconds ([\fBlindex\fR $result 0])
50 .IP \(bu 3
51 the count how many times it was executed ([\fBlindex\fR $result 2])
52 .IP \(bu 3
53 the estimated rate per second ([\fBlindex\fR $result 4])
54 .IP \(bu 3
55 the estimated real execution time without measurement overhead ([\fBlindex\fR $result 6])
56 .PP
57 The following options may be supplied to the \fBtimerate\fR command:
58 .TP
59 \fB\-calibrate\fR
60 .
61 To measure very fast scripts as exactly as possible, a calibration process
62 may be required.
63 The \fB\-calibrate\fR option is used to calibrate \fBtimerate\fR itself,
64 calculating the estimated overhead of the given script as the default overhead
65 for future invocations of the \fBtimerate\fR command. If the \fItime\fR
66 parameter is not specified, the calibrate procedure runs for up to 10 seconds.
67 .RS
68 .PP
69 Note that calibration is not thread safe in the current implementation.
70 .RE
71 .TP
72 \fB\-overhead \fIdouble\fR
73 .
74 The \fB\-overhead\fR parameter supplies an estimate (in microseconds) of the
75 measurement overhead of each iteration of the tested script. The passed value
76 overrides, for the current invocation of \fBtimerate\fR, the overhead
77 estimated by a previous calibration. Overrides may themselves be measured
78 using \fBtimerate\fR as illustrated by a later example.
79 .TP
80 \fB\-direct\fR
81 .
82 The \fB-direct\fR option causes direct execution of the supplied script,
83 without compilation, in a manner similar to the \fBtime\fR command. It can be
84 used to measure the cost of \fBTcl_EvalObjEx\fR, of the invocation of canonical
85 lists, and of the uncompiled versions of bytecoded commands.
86 .PP
87 As opposed to the \fBtime\fR commmand, which runs the tested script for a fixed
88 number of iterations, the timerate command runs it for a fixed time.
89 Additionally, the compiled variant of the script will be used during the entire
90 measurement, as if the script were part of a compiled procedure, if the \fB\-direct\fR
91 option is not specified. The fixed time period and possibility of compilation allow
92 for more precise results and prevent very long execution times by slow scripts, making
93 it practical for measuring scripts with highly uncertain execution times.
94 .SH EXAMPLES
95 Estimate how fast it takes for a simple Tcl \fBfor\fR loop (including
96 operations on variable \fIi\fR) to count to ten:
97 .PP
98 .CS
99 \fI# calibrate\fR
100 \fBtimerate\fR -calibrate {}
101
102 \fI# measure\fR
103 \fBtimerate\fR { for {set i 0} {$i<10} {incr i} {} } 5000
104 .CE
105 .PP
106 Estimate how fast it takes for a simple Tcl \fBfor\fR loop, ignoring the
107 overhead of the management of the variable that controls the loop:
108 .PP
109 .CS
110 \fI# calibrate for overhead of variable operations\fR
111 set i 0; \fBtimerate\fR -calibrate {expr {$i<10}; incr i} 1000
112
113 \fI# measure\fR
114 \fBtimerate\fR {
115 for {set i 0} {$i<10} {incr i} {}
116 } 5000
117 .CE
118 .PP
119 Estimate the speed of calculating the hour of the day using \fBclock format\fR only,
120 ignoring overhead of the portion of the script that prepares the time for it to
121 calculate:
122 .PP
123 .CS
124 \fI# calibrate\fR
125 \fBtimerate\fR -calibrate {}
126
127 \fI# estimate overhead\fR
128 set tm 0
129 set ovh [lindex [\fBtimerate -overhead 0\fR {
130 incr tm [expr {24*60*60}]
131 }] 0]
132
133 \fI# measure using estimated overhead\fR
134 set tm 0
135 \fBtimerate\fR -overhead $ovh {
136 clock format $tm -format %H
137 incr tm [expr {24*60*60}]; # overhead for this is ignored
138 } 5000
139 .CE
140 .PP
141 In this last example, note that the overhead itself is measured using
142 \fBtimerate\fR invoked with \fB-overhead 0\fR. This is necessary
143 because explicit overheads are assumed to be absolute values,
144 and not an increment over the default calibrated overhead. It is
145 therefore important that the calibrated overhead is excluded in the
146 measurement of the overhead value itself. This is accomplished by
147 passing \fB-overhead 0\fR when measuring the overhead.
148 .SH "SEE ALSO"
149 time(n)
150 .SH KEYWORDS
151 performance measurement, script, time
152 .\" Local Variables:
153 .\" mode: nroff
154 .\" End: