]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wxSWIG/swig_lib/timers.i
unicode compilation fix
[wxWidgets.git] / wxPython / wxSWIG / swig_lib / timers.i
1 //
2 // $Header$
3 //
4 // timers.i
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.
8 //
9 // Dave Beazley
10 // April 2, 1996
11 //
12 /* Revision history
13 * $Log$
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.
23 *
24 * Revision 1.1.1.1 1999/02/28 02:00:53 beazley
25 * Swig1.1
26 *
27 * Revision 1.1 1996/05/22 17:27:01 beazley
28 * Initial revision
29 *
30 */
31
32 %module timers
33 %{
34
35 #include <time.h>
36 #define SWIG_NTIMERS 64
37
38 static clock_t telapsed[SWIG_NTIMERS];
39 static clock_t tstart[SWIG_NTIMERS];
40 static clock_t tend[SWIG_NTIMERS];
41
42 /*-----------------------------------------------------------------
43 * SWIG_timer_clear(int i)
44 *
45 * Clears timer i.
46 *----------------------------------------------------------------- */
47
48 void
49 SWIG_timer_clear(int i)
50 {
51 if ((i >= 0) && (i < SWIG_NTIMERS))
52 telapsed[i] = 0;
53 }
54
55
56 /*-----------------------------------------------------------------
57 * SWIG_timer_start(int i)
58 *
59 * Starts timer i
60 *----------------------------------------------------------------- */
61
62 void
63 SWIG_timer_start(int i)
64 {
65 if ((i >= 0) && (i < SWIG_NTIMERS))
66 tstart[i] = clock();
67 }
68
69
70 /*-----------------------------------------------------------------
71 * SWIG_timer_stop(int i)
72 *
73 * Stops timer i and accumulates elapsed time
74 *----------------------------------------------------------------- */
75
76 void
77 SWIG_timer_stop(int i)
78 {
79 if ((i >= 0) && (i < SWIG_NTIMERS)) {
80 tend[i] = clock();
81 telapsed[i] += (tend[i] - tstart[i]);
82 }
83 }
84
85 /*-----------------------------------------------------------------
86 * SWIG_timer_elapsed(int i)
87 *
88 * Returns the time elapsed on timer i in seconds.
89 *----------------------------------------------------------------- */
90
91 double
92 SWIG_timer_elapsed(int i)
93 {
94 double t;
95 if ((i >= 0) && (i < SWIG_NTIMERS)) {
96 t = (double) telapsed[i]/(double) CLOCKS_PER_SEC;
97 return(t);
98 } else {
99 return 0;
100 }
101 }
102
103 %}
104
105 %section "Timer Functions",pre,after,chop_left=3,nosort,info,chop_right = 0, chop_top=0,chop_bottom=0
106
107 %text %{
108 %include timers.i
109
110 This module provides a collection of timing functions designed for
111 performance analysis and benchmarking of different code fragments.
112
113 A total of 64 different timers are available. Each timer can be
114 managed independently using four functions :
115
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)
120
121 All timers measure CPU time.
122
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 :
126 %}
127
128 #if defined(SWIGTCL)
129 %text %{
130 timer_clear 0
131 timer_start 0
132 .. a bunch of Tcl code ...
133 timer_stop 0
134 puts "[timer_elapsed 0] seconds of CPU time"
135 %}
136 #elif defined(SWIGPERL)
137 %text %{
138 timer_clear(0);
139 timer_start(0);
140 .. a bunch of Perl code ...
141 timer_stop(0);
142 print timer_elapsed(0)," seconds of CPU time\n";
143 %}
144 #elif defined(SWIGPYTHON)
145 %text %{
146 timer_clear(0)
147 timer_start(0)
148 ... a bunch of Python code ...
149 timer_stop(0)
150 print timer_elapsed(0)," seconds of CPU time"
151 %}
152 #endif
153
154 %text %{
155 A single timer can be stopped and started repeatedly to provide
156 a cummulative timing effect.
157
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.
163 %}
164
165
166 %name(timer_clear) void SWIG_timer_clear(int n);
167 /* Clears timer n. */
168
169 %name(timer_start) void SWIG_timer_start(int n);
170 /* Starts timer n. */
171
172 %name(timer_stop) void SWIG_timer_stop(int n);
173 /* Stops timer n. */
174
175 %name(timer_elapsed) double SWIG_timer_elapsed(int n);
176 /* Return the elapsed time (in seconds) of timer n */
177
178
179
180