blob: 553d76f7f70f04b16355cacfbdb510190b2f2d06 [file] [log] [blame]
Guido van Rossum116857c1994-01-02 23:22:21 +00001/*
2 * Copyright (c) 1993 George V. Neville-Neil
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
Guido van Rossumb1ba7502008-04-01 23:57:36 +000013 * 3. The name, George Neville-Neil may not be used to endorse or promote
14 * products derived from this software without specific prior
Guido van Rossum116857c1994-01-02 23:22:21 +000015 * written permission.
16 *
Guido van Rossumb1ba7502008-04-01 23:57:36 +000017 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
Guido van Rossum116857c1994-01-02 23:22:21 +000018 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
Guido van Rossum116857c1994-01-02 23:22:21 +000030#ifndef _TIMING_H_
31#define _TIMING_H_
32
Guido van Rossumcbcd8d71994-01-14 16:55:50 +000033#ifdef TIME_WITH_SYS_TIME
Guido van Rossum116857c1994-01-02 23:22:21 +000034#include <sys/time.h>
Guido van Rossumcbcd8d71994-01-14 16:55:50 +000035#include <time.h>
36#else /* !TIME_WITH_SYS_TIME */
37#ifdef HAVE_SYS_TIME_H
38#include <sys/time.h>
39#else /* !HAVE_SYS_TIME_H */
40#include <time.h>
41#endif /* !HAVE_SYS_TIME_H */
42#endif /* !TIME_WITH_SYS_TIME */
Guido van Rossum116857c1994-01-02 23:22:21 +000043
44static struct timeval aftertp, beforetp;
45
46#define BEGINTIMING gettimeofday(&beforetp, NULL)
47
48#define ENDTIMING gettimeofday(&aftertp, NULL); \
49 if(beforetp.tv_usec > aftertp.tv_usec) \
50 { \
51 aftertp.tv_usec += 1000000; \
52 aftertp.tv_sec--; \
53 }
54
55#define TIMINGUS (((aftertp.tv_sec - beforetp.tv_sec) * 1000000) + \
56 (aftertp.tv_usec - beforetp.tv_usec))
57
58#define TIMINGMS (((aftertp.tv_sec - beforetp.tv_sec) * 1000) + \
59 ((aftertp.tv_usec - beforetp.tv_usec) / 1000))
60
61#define TIMINGS ((aftertp.tv_sec - beforetp.tv_sec) + \
62 (aftertp.tv_usec - beforetp.tv_usec) / 1000000)
63
64#endif /* _TIMING_H_ */