Alien-Judy

 view release on metacpan or  search on metacpan

src/judy-1.0.5/test/timeit.h  view on Meta::CPAN

#ifndef _TIMEIT_H
#define	_TIMEIT_H

// @(#) $Revision: 4.14 $ $Source: /judy/src/apps/benchmark/timeit.h $
//
// Timing and timers header file with example program.
//
// You should compile with one of these defined:
//
//   JU_HPUX_PA		# control register available (via asm()).
//   JU_HPUX_IPF	# TBD, see below.
//   JU_LINUX_IA32	# control register available (via get_cycles()).
//   JU_LINUX_IPF	# control register available (via get_cycles()).
//   JU_WIN_IA32	# uses clock().
//
// Otherwise default (low-res) timing code using gettimeofday() results.  This
// mode is only accurate to usecs, and fuzzy due to syscall overhead.
//
// Public macros; the *_HRTm() forms are much faster than the others:
//
// TIMER_vars(T) - declare variables to use for timers
// STARTTm(T)    - start the timer with variable T
// ENDTm(D,T)    - compute usec from last STARTTm(T), save result in double D
// START_HRTm(T) - high-res for short intervals (< 2^32[64] clock ticks) only
// END_HRTm(D,T) - high-res for short intervals (< 2^32[64] clock ticks) only
//
// Private macros:
//
// __START_HRTm(T) - read high-res control register, save in T
// __END_HRTm(T)   - read high-res control register, save in T
// __HRONLY(D,T)   - use high-res clock only
//
// Note:  The __*_HRTm and __HRONLY macros are only available on platforms with
// control registers for high-res clocks.  On hpux_pa this is a 32-bit register
// and gettimeofday() must be used to handle rollover; on linux_* this is a
// 64-bit register.

#ifndef JU_WIN_IA32
#include <sys/time.h>		// Win32 uses a whole different paradigm.
#include <unistd.h>		// for getopt(), which Win32 lacks.
#endif

#include <time.h>

// Public variables:

extern double USecPerClock;	// defined in timeit.c.

// __HRONLY is used for multiple platforms, but only in cases where there is a
// high-res clock and find_CPU_speed() is available from timeit.c:

#define	__HRONLY(D,T)							\
	{								\
	    if (USecPerClock == 0.0) USecPerClock = find_CPU_speed();   \
	    (D) = ((double) (__stop_##T - __start_##T)) * USecPerClock; \
	}


// TIMING ROUTINES:


// ********************* HPUX PA ****************************
//
// Define __START_HRTm and __END_HRTm only, and let later common code add
// STARTTm and ENDTm.
//
// TBD:  On hpux_pa or hpux_ipf 64-bit, is CR_IT a 64-bit register?  If so, it's
// unnecessary and wasteful to use gettimeofday() later to watch for rollover.
//
// TBD:  JU_HPUX_IPF does not recognize CR_IT ("Undeclared variable 'CR_IT'"),
// so for now treat that platform as having no high-res clock and do not
// included it in this section.

#if (JU_HPUX_PA)
#include <machine/reg.h>
#include <sys/pstat.h>

double find_CPU_speed(void);

// Note:  On hpux_*, at least older compilers, it is neither necessary nor even
// allowed to mark the __start_* and __stop_* variables as volatile; the
// compiler does not optimize out the code even without it:



( run in 1.352 second using v1.01-cache-2.11-cpan-6aa56a78535 )