home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyth_os2.zip / python-1.0.2 / Modules / timing.h < prev    next >
C/C++ Source or Header  |  1994-01-14  |  3KB  |  100 lines

  1. /*
  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.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by George V. Neville-Neil
  16.  * 4. The name, George Neville-Neil may not be used to endorse or promote 
  17.  *    products derived from this software without specific prior 
  18.  *    written permission.
  19.  *
  20.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 
  21.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
  24.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  26.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  29.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30.  * SUCH DAMAGE.
  31.  */
  32.  
  33. /*
  34.  *
  35.  * File: $Id: timing.h,v 2.2 1994/01/14 16:55:47 guido Exp $
  36.  *
  37.  * Author: George V. Neville-Neil
  38.  *
  39.  * Update History: $Log: timing.h,v $
  40.  * Revision 2.2  1994/01/14  16:55:47  guido
  41.  * Make more robust against Minix and Mac
  42.  *
  43.  * Revision 2.1  1994/01/02  23:22:19  guido
  44.  * Added George Neville-Neil's timing module
  45.  *
  46.  * Revision 1.1  93/12/28  13:14:19  gnn
  47.  * Initial revision
  48.  * 
  49.  * Revision 1.1  93/12/23  18:59:10  gnn
  50.  * Initial revision
  51.  * 
  52.  * Revision 1.3  93/07/22  15:57:39  15:57:39  gnn (George Neville-Neil)
  53.  * Added copyright message.
  54.  * 
  55.  * Revision 1.2  1993/07/22  12:12:34  gnn
  56.  * Latest macros.  They now evaluate to rvalues.
  57.  *
  58.  * Revision 1.1  93/07/19  16:56:18  16:56:18  gnn (George Neville-Neil)
  59.  * Initial revision
  60.  * 
  61.  *
  62.  *
  63.  */
  64.  
  65. #ifndef _TIMING_H_
  66. #define _TIMING_H_
  67.  
  68. #ifdef TIME_WITH_SYS_TIME
  69. #include <sys/time.h>
  70. #include <time.h>
  71. #else /* !TIME_WITH_SYS_TIME */
  72. #ifdef HAVE_SYS_TIME_H
  73. #include <sys/time.h>
  74. #else /* !HAVE_SYS_TIME_H */
  75. #include <time.h>
  76. #endif /* !HAVE_SYS_TIME_H */
  77. #endif /* !TIME_WITH_SYS_TIME */
  78.  
  79. static struct timeval aftertp, beforetp;
  80.  
  81. #define BEGINTIMING gettimeofday(&beforetp, NULL)
  82.  
  83. #define ENDTIMING gettimeofday(&aftertp, NULL); \
  84.     if(beforetp.tv_usec > aftertp.tv_usec) \
  85.     {  \
  86.          aftertp.tv_usec += 1000000;  \
  87.          aftertp.tv_sec--; \
  88.     }
  89.  
  90. #define TIMINGUS (((aftertp.tv_sec - beforetp.tv_sec) * 1000000) + \
  91.           (aftertp.tv_usec - beforetp.tv_usec))
  92.  
  93. #define TIMINGMS (((aftertp.tv_sec - beforetp.tv_sec) * 1000) + \
  94.           ((aftertp.tv_usec - beforetp.tv_usec) / 1000))
  95.  
  96. #define TIMINGS  ((aftertp.tv_sec - beforetp.tv_sec) + \
  97.           (aftertp.tv_usec - beforetp.tv_usec) / 1000000)
  98.  
  99. #endif /* _TIMING_H_ */
  100.