home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 September
/
Simtel20_Sept92.cdr
/
msdos
/
progjorn
/
pj_6_3.arc
/
TIMER1
< prev
next >
Wrap
Text File
|
1988-04-05
|
2KB
|
80 lines
Code from Redirections, "Pink Noise" by Frank D. Greco.
Copyright 1988 by Frank D. Greco. No commercial use of this code
without express permission of the author.
/*
* TIMER.H -- Header file for timing programs
*
* When including and compiling with your programs:
*
* System V
* $ cc -DSYSV program.c ... other files ...
*
* Berkeley-based Unix
* % cc -DBSD program.c ... other files ...
*
* PC and Microsoft C [timing granularity 1/18 second]
* C:\> cl -DPC program.c ... other files ...
*
* PC and Microsoft C [timing granularity 1/1000 second]
* C:\> cl -DPC -DFAST_CLOCK program.c ... other files ...
*
*/
#define DEBUG /* Turn on timing statistics */
#define TIX_DIFF (_t2 - _t1)
/***************** For Berkeley Versions of Unix ****************/
#ifdef BSD
# include <sys/types.h>
# include <sys/time.h>
static double _t1, _t2;
static struct timeval _tv_;
static struct timeval _timez;
# define gettime() gettimeofday(&_tv_, &_timez_)
# define START() (gettime(), _t1 = _tv_.tv_usec/1e6 + _tv_.tv_sec)
# define STOP() (gettime(), _t2 = _tv_.tv_usec/1e6 + _tv_.tv_sec)
# define PRINT_TIME(cp) fprintf(stderr,"%s: %lf secs.\n",cp,TIX_DIFF)
#endif
/***************** For System V Versions of Unix ****************/
#ifdef SYSV
# include <sys/types.h>
# include <sys/times.h>
static struct tms _currtime;
long times();
static long _t1, _t2;
# define gettime() times(&_currtime)
# define TIX_PER_SEC 60.0 /* Verify for Your Machine */
/* For the 3B2 use 100.0 */
# define START() _t1 = gettime()
# define STOP() _t2 = gettime()
# define PRINT_TIME(cp) fprintf(stderr,"%s: %lf secs.\n", \
cp, TIX_DIFF / TIX_PER_SEC)
#endif
/***************** For the PC ****************/
#ifdef PC
# ifdef FAST_CLOCK
# define TIX_PER_SEC 1000.0
# else
# define TIX_PER_SEC 18.20648
# endif
unsigned long gettime();
static long _t1, _t2; /* Tick values for calc. elapsed time */
# define START() _t1 = gettime()
# define STOP() _t2 = gettime()
# define PRINT_TIME(cp) fprintf(stderr,"%s: %lf secs.\n", \
cp, TIX_DIFF / TIX_PER_SEC)
#endif
#ifdef DEBUG
# define TIME(code, string) START(); code; STOP(); PRINT_TIME(string)
#else
# define TIME(code, string) code
#endif