Alien-Judy
view release on metacpan or search on metacpan
src/judy-1.0.5/test/timeit.c view on Meta::CPAN
ztime = 0.0;
for (i = 0; i < 100; ++i) // average many runs.
{
STARTTm(tm2);
ENDTm(DeltaUSec, tm2);
ztime += DeltaUSec;
}
ztime = ztime / ((double) i);
// SIMPLE TESTS OF TIMER OVERHEAD:
//
// Make two passes at both the high-res (if any) and slower timers.
(void) puts("\nTiming timers themselves: start, end, end");
#define PRINTPASS(Desc,Pass) \
(void) printf("%-8s pass %d: %f - %f = %f usec\n", Desc, Pass, \
usec[((Pass) * 2) - 1], usec[((Pass) * 2) - 2], \
usec[((Pass) * 2) - 1] - usec[((Pass) * 2) - 2])
#ifdef _TIMEIT_HIGHRES
START_HRTm(tm2);
END_HRTm(usec[0], tm2); // throw away in case of sleep(1) here.
START_HRTm(tm2);
END_HRTm(usec[0], tm2);
END_HRTm(usec[1], tm2);
START_HRTm(tm2);
END_HRTm(usec[2], tm2);
END_HRTm(usec[3], tm2);
PRINTPASS("High-res", 1);
PRINTPASS("High-res", 2);
#endif
STARTTm(tm2);
ENDTm(usec[0], tm2); // throw away in case of sleep(1) here.
STARTTm(tm2);
ENDTm(usec[0], tm2);
ENDTm(usec[1], tm2);
STARTTm(tm2);
ENDTm(usec[2], tm2);
ENDTm(usec[3], tm2);
PRINTPASS("Non-HR", 1);
PRINTPASS("Non-HR", 2);
// PRINT INITIAL INFO:
#ifdef _TIMEIT_HIGHRES
// Print the CPU speed:
//
// Note: USecPerClock is a global set by the first instance of STARTTm. You
// can also get this number by calling find_CPU_speed().
(void) printf("\nClock step = %.3f nsec => %.1f MHz.\n",
USecPerClock * 1000.0, 1.0 / USecPerClock);
#endif
// Print timer overhead even though it's been subtracted from the reported
// results.
(void) printf("Timer overhead subtracted from the times below = %f "
"usec.\n", ztime);
// DO A FAST TIMER CHECK:
(void) puts("\nCheck timer precision by repeating the same action:");
(void) puts("Times in each group should be close together.");
(void) puts("\nTiming something very fast: \"++i\":");
mintime = MAXDOUBLE;
for (i = 1; i <= i_max; ++i)
{
prevtime = DeltaUSec;
STARTTm(tm2); // start the timer.
++i; // statement to time.
ENDTm(DeltaUSec, tm2); // stop the timer.
DeltaUSec -= ztime; // remove timer overhead.
// Throw away the first loop iteration to warm up the cache:
if (--i > preload)
{
if (mintime == MAXDOUBLE) mintime = DeltaUSec;
(void) printf("%3d. %8.3f nanosec,\tmintime diff %8.1f %%\n",
i - preload, DeltaUSec * 1000.0,
((DeltaUSec - mintime) * 100) / mintime);
if (DeltaUSec < mintime) mintime = DeltaUSec;
}
}
// TIME A FUNCTION CALL:
(void) puts("\nTiming a function: \"gettimeofday()\":");
mintime = MAXDOUBLE;
for (i = 1; i <= i_max; ++i)
{
prevtime = DeltaUSec;
STARTTm(tm2); // start the timer.
gettimeofday(&tmjunk, NULL); // burn some cycles.
ENDTm(DeltaUSec, tm2); // stop the timer.
DeltaUSec -= ztime; // remove timer overhead.
// Throw away the first loop iteration to warm up the cache:
if (i > preload)
( run in 0.537 second using v1.01-cache-2.11-cpan-e1769b4cff6 )