5 // A SWIG file for adding various timing functions.
6 // Really, this is modeled after the timers in the CMMD
7 // message passing library for the CM-5.
14 * Revision 1.1 2002/04/29 19:56:49 RD
15 * Since I have made several changes to SWIG over the years to accomodate
16 * special cases and other things in wxPython, and since I plan on making
17 * several more, I've decided to put the SWIG sources in wxPython's CVS
18 * instead of relying on maintaining patches. This effectivly becomes a
19 * fork of an obsolete version of SWIG, :-( but since SWIG 1.3 still
20 * doesn't have some things I rely on in 1.1, not to mention that my
21 * custom patches would all have to be redone, I felt that this is the
22 * easier road to take.
24 * Revision 1.1.1.1 1999/02/28 02:00:53 beazley
27 * Revision 1.1 1996/05/22 17:27:01 beazley
36 #define SWIG_NTIMERS 64
38 static clock_t telapsed[SWIG_NTIMERS];
39 static clock_t tstart[SWIG_NTIMERS];
40 static clock_t tend[SWIG_NTIMERS];
42 /*-----------------------------------------------------------------
43 * SWIG_timer_clear(int i)
46 *----------------------------------------------------------------- */
49 SWIG_timer_clear(int i)
51 if ((i >= 0) && (i < SWIG_NTIMERS))
56 /*-----------------------------------------------------------------
57 * SWIG_timer_start(int i)
60 *----------------------------------------------------------------- */
63 SWIG_timer_start(int i)
65 if ((i >= 0) && (i < SWIG_NTIMERS))
70 /*-----------------------------------------------------------------
71 * SWIG_timer_stop(int i)
73 * Stops timer i and accumulates elapsed time
74 *----------------------------------------------------------------- */
77 SWIG_timer_stop(int i)
79 if ((i >= 0) && (i < SWIG_NTIMERS)) {
81 telapsed[i] += (tend[i] - tstart[i]);
85 /*-----------------------------------------------------------------
86 * SWIG_timer_elapsed(int i)
88 * Returns the time elapsed on timer i in seconds.
89 *----------------------------------------------------------------- */
92 SWIG_timer_elapsed(int i)
95 if ((i >= 0) && (i < SWIG_NTIMERS)) {
96 t = (double) telapsed[i]/(double) CLOCKS_PER_SEC;
105 %section "Timer Functions",pre,after,chop_left=3,nosort,info,chop_right = 0, chop_top=0,chop_bottom=0
110 This module provides a collection of timing functions designed for
111 performance analysis and benchmarking of different code fragments.
113 A total of 64 different timers are available. Each timer can be
114 managed independently using four functions :
116 timer_clear(int n) Clears timer n
117 timer_start(int n) Start timer n
118 timer_stop(int n) Stop timer n
119 timer_elapsed(int n) Return elapsed time (in seconds)
121 All timers measure CPU time.
123 Since each timer can be accessed independently, it is possible
124 to use groups of timers for measuring different aspects of code
125 performance. To use a timer, simply use code like this :
132 .. a bunch of Tcl code ...
134 puts "[timer_elapsed 0] seconds of CPU time"
136 #elif defined(SWIGPERL)
140 .. a bunch of Perl code ...
142 print timer_elapsed(0)," seconds of CPU time\n";
144 #elif defined(SWIGPYTHON)
148 ... a bunch of Python code ...
150 print timer_elapsed(0)," seconds of CPU time"
155 A single timer can be stopped and started repeatedly to provide
156 a cummulative timing effect.
158 As a general performance note, making frequent calls to the timing
159 functions can severely degrade performance (due to operating system
160 overhead). The resolution of the timers may be poor for extremely
161 short code fragments. Therefore, the timers work best for
162 computationally intensive operations.
166 %name(timer_clear) void SWIG_timer_clear(int n);
167 /* Clears timer n. */
169 %name(timer_start) void SWIG_timer_start(int n);
170 /* Starts timer n. */
172 %name(timer_stop) void SWIG_timer_stop(int n);
175 %name(timer_elapsed) double SWIG_timer_elapsed(int n);
176 /* Return the elapsed time (in seconds) of timer n */