annotate Modules/timing.h @ 16798:258dcafe2d0b legacy-trunk

Gustavo Niemeyer <niemeyer@conectiva.com>: Fixed recno support (keys are integers rather than strings). Work around DB bug that cause stdin to be closed by rnopen() when the DB file needed to exist but did not (no longer segfaults). This closes SF tracker patch #403445. Also wrapped some long lines and added whitespace around operators -- FLD.
author Fred Drake <fdrake@acm.org>
date Tue, 27 Feb 2001 18:56:46 +0000
parents af1c2f36dc34
children 1c78d8e87653
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1474
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 /*
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 * Copyright (c) 1993 George V. Neville-Neil
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 * All rights reserved.
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 *
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 * Redistribution and use in source and binary forms, with or without
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 * modification, are permitted provided that the following conditions
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 * are met:
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 * 1. Redistributions of source code must retain the above copyright
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 * notice, this list of conditions and the following disclaimer.
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 * 2. Redistributions in binary form must reproduce the above copyright
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 * notice, this list of conditions and the following disclaimer in the
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 * documentation and/or other materials provided with the distribution.
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 * 3. All advertising materials mentioning features or use of this software
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 * must display the following acknowledgement:
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 * This product includes software developed by George V. Neville-Neil
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 * 4. The name, George Neville-Neil may not be used to endorse or promote
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 * products derived from this software without specific prior
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 * written permission.
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 *
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 * SUCH DAMAGE.
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 */
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
32
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 #ifndef _TIMING_H_
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 #define _TIMING_H_
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
35
1520
8e97a68b2b17 Make more robust against Minix and Mac
Guido van Rossum <guido@python.org>
parents: 1474
diff changeset
36 #ifdef TIME_WITH_SYS_TIME
1474
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 #include <sys/time.h>
1520
8e97a68b2b17 Make more robust against Minix and Mac
Guido van Rossum <guido@python.org>
parents: 1474
diff changeset
38 #include <time.h>
8e97a68b2b17 Make more robust against Minix and Mac
Guido van Rossum <guido@python.org>
parents: 1474
diff changeset
39 #else /* !TIME_WITH_SYS_TIME */
8e97a68b2b17 Make more robust against Minix and Mac
Guido van Rossum <guido@python.org>
parents: 1474
diff changeset
40 #ifdef HAVE_SYS_TIME_H
8e97a68b2b17 Make more robust against Minix and Mac
Guido van Rossum <guido@python.org>
parents: 1474
diff changeset
41 #include <sys/time.h>
8e97a68b2b17 Make more robust against Minix and Mac
Guido van Rossum <guido@python.org>
parents: 1474
diff changeset
42 #else /* !HAVE_SYS_TIME_H */
8e97a68b2b17 Make more robust against Minix and Mac
Guido van Rossum <guido@python.org>
parents: 1474
diff changeset
43 #include <time.h>
8e97a68b2b17 Make more robust against Minix and Mac
Guido van Rossum <guido@python.org>
parents: 1474
diff changeset
44 #endif /* !HAVE_SYS_TIME_H */
8e97a68b2b17 Make more robust against Minix and Mac
Guido van Rossum <guido@python.org>
parents: 1474
diff changeset
45 #endif /* !TIME_WITH_SYS_TIME */
1474
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
46
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 static struct timeval aftertp, beforetp;
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
48
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 #define BEGINTIMING gettimeofday(&beforetp, NULL)
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
50
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 #define ENDTIMING gettimeofday(&aftertp, NULL); \
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 if(beforetp.tv_usec > aftertp.tv_usec) \
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 { \
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 aftertp.tv_usec += 1000000; \
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 aftertp.tv_sec--; \
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 }
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
57
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 #define TIMINGUS (((aftertp.tv_sec - beforetp.tv_sec) * 1000000) + \
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 (aftertp.tv_usec - beforetp.tv_usec))
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
60
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 #define TIMINGMS (((aftertp.tv_sec - beforetp.tv_sec) * 1000) + \
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 ((aftertp.tv_usec - beforetp.tv_usec) / 1000))
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
63
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 #define TIMINGS ((aftertp.tv_sec - beforetp.tv_sec) + \
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 (aftertp.tv_usec - beforetp.tv_usec) / 1000000)
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
66
2064b16709f2 Added George Neville-Neil's timing module
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 #endif /* _TIMING_H_ */