Alien-Judy
view release on metacpan or search on metacpan
src/judy-1.0.5/test/Judy1LHTime.c view on Meta::CPAN
// @(#) $Revision: 4.20 $ $Source: /judy/test/manual/Judy1LHTime.c $
//=======================================================================
// This program measures the performance of a Judy1 and JudyL Array.
// -by-
// Author Douglas L. Baskins, Aug 2003.
// Permission to use this code is freely granted, provided that this
// statement is retained.
// email - dougbaskins@yahoo.com
//=======================================================================
#include <unistd.h> // sbrk()
#include <stdlib.h> // exit()
#include <stdio.h> // printf(), setbuf()
#include <math.h> // pow()
#include <sys/time.h> // gettimeofday()
#include <sys/utsname.h> // uname()
#include <Judy.h> // for Judy macros J*()
//#include <JudyHS.h> // compiling with old Judy.h without JudyHS
#ifdef NOINLINE /* this is the 21st century? */
#define _INLINE_ static
#else
#define _INLINE_ inline
#endif
//=======================================================================
// This program measures the performance of a Judy1, JudyL and
// limited to one size of string (sizeof Word_t) JudyHS Arrays.
//
// Compile:
//
// cc -O Judy1LHTime.c -lm -lJudy -o Judy1LHTime
// -or-
// cc -O -DCPUMHZ=2400 Judy1LHTime.c -lm -lJudy -o Judy1LHTime
/* Notes:
1) Use '-DCPUMHZ=2400' in cc line if better clock resolution is desired
and it compiles successfully. The 2400 is the cpu MHz : 2400 -or-
cat /proc/cpuinfo | grep "cpu MHz" in a Linux system.
2)
*/
//=======================================================================
// T I M I N G M A C R O S
//=======================================================================
double DeltaUSec; // Global for remembering delta times
#ifdef CPUMHZ
// For a 1.34 nS clock cycle processor (750Mhz)
#define CPUSPEED (1.0 / (CPUMHZ))
//#define rdtscll(val) __asm__ __volatile__("rdtsc" : "=A" (val))
#define rdtscl(low) __asm__ __volatile__("rdtsc" : "=a" (low) : : "edx")
static inline uint32_t
get_cycles(void)
{
uint32_t ret = 0;
rdtscl(ret);
return (ret);
}
#define STARTTm \
{ \
gettimeofday(&TVBeg__, NULL); \
GCBeg__ = get_cycles(); \
}
#define ENDTm(D) \
{ \
uint32_t GCEnd__; \
GCEnd__ = get_cycles(); \
gettimeofday(&TVEnd__, NULL); \
(D) = (double)(TVEnd__.tv_sec - TVBeg__.tv_sec) * 1E6 + \
((double)(TVEnd__.tv_usec - TVBeg__.tv_usec)); \
if (D < 10000.0) D = (double)(GCEnd__ - GCBeg__) * CPUSPEED; \
}
#else // ! CPUMHZ
#define STARTTm gettimeofday(&TVBeg__, NULL)
#define ENDTm(D) \
{ \
gettimeofday(&TVEnd__, NULL); \
(D) = (double)(TVEnd__.tv_sec - TVBeg__.tv_sec) * 1E6 + \
((double)(TVEnd__.tv_usec - TVBeg__.tv_usec)); \
}
#endif // ! CPUMHZ
// ****************************************************************************
// J U D Y M A L L O C
//
// Allocate RAM. This is the single location in Judy code that calls
// malloc(3C). Note: JPM accounting occurs at a higher level.
enum
{
JudyMal1,
JudyMalL,
JudyMalHS
} MalFlag;
static Word_t MalFreeCnt = 0;
Word_t TotJudy1MemUsed = 0;
src/judy-1.0.5/test/Judy1LHTime.c view on Meta::CPAN
}
} // Groups = number of sizes
//============================================================
// PRINT HEADER TO PERFORMANCE TIMERS
//============================================================
Col = 1;
printf("# COLHEAD %d Population\n", Col++);
printf("# COLHEAD %d Measurments\n", Col++);
printf("# COLHEAD %d J1S - Judy1Set\n", Col++);
printf("# COLHEAD %d JLI - JudyLIns\n", Col++);
printf("# COLHEAD %d JHSI - JudyHSIns\n", Col++);
printf("# COLHEAD %d J1T - Judy1Test\n", Col++);
printf("# COLHEAD %d JLG - JudyLGet\n", Col++);
printf("# COLHEAD %d JHSG - JudyHSGet\n", Col++);
if (IFlag)
{
printf("# COLHEAD %d J1S-dup\n", Col++);
printf("# COLHEAD %d JLI-dup\n", Col++);
printf("# COLHEAD %d JHSI-dup\n", Col++);
}
if (cFlag)
{
printf("# COLHEAD %d Copy J1T->J1S\n", Col++);
}
if (CFlag)
{
printf("# COLHEAD %d J1C\n", Col++);
printf("# COLHEAD %d JLC\n", Col++);
}
if (vFlag)
{
printf("# COLHEAD %d J1N\n", Col++);
printf("# COLHEAD %d JLN\n", Col++);
printf("# COLHEAD %d J1P\n", Col++);
printf("# COLHEAD %d JLP\n", Col++);
printf("# COLHEAD %d J1NE\n", Col++);
printf("# COLHEAD %d JLNE\n", Col++);
printf("# COLHEAD %d J1PE\n", Col++);
printf("# COLHEAD %d JLPE\n", Col++);
}
if (dFlag)
{
printf("# COLHEAD %d J1U\n", Col++);
printf("# COLHEAD %d JLD\n", Col++);
printf("# COLHEAD %d JHSD\n", Col++);
}
printf("# COLHEAD %d 1heap/I - Judy1 heap memery per Index\n", Col++);
printf("# COLHEAD %d Lheap/I - JudyL heap memery per Index\n", Col++);
printf("# COLHEAD %d HSheap/I - JudyHS heap memery per Index\n", Col++);
printf("# COLHEAD %d MF1/I - Judy1 malloc+free's per delta Indexes\n",
Col++);
printf("# COLHEAD %d MFL/I - JudyL malloc+free's per delta Indexes\n",
Col++);
printf("# COLHEAD %d MFHS/I - JudyHS malloc+free's per delta Indexes\n",
Col++);
#ifdef CPUMHZ
printf("#\n# Compiled for processor speed of %d Mhz\n#\n", CPUMHZ);
#endif // CPUMHZ
printf("# %s - Leaf sizes in Words\n", Judy1MallocSizes);
printf("# %s - Leaf sizes in Words\n#\n", JudyLMallocSizes);
printf("# Pop1 Measmts J1S JLI JHSI J1T JLG JHSG");
if (IFlag)
printf(" dupJ1S dupJLI dupJHI");
if (cFlag)
printf(" CopyJ1");
if (CFlag)
printf(" J1C JLC");
if (vFlag)
printf(" J1N JLN J1P JLP J1NE JLNE J1PE JLPE");
if (dFlag)
printf(" J1U JLD JHSD");
printf(" 1heap/I Lheap/I HSheap/I");
printf(" MF1/I");
printf(" MFL/I");
printf(" MFHS/I");
printf("\n");
//============================================================
// BEGIN TESTS AT EACH GROUP SIZE
//============================================================
// Get the kicker to test the LFSR
FirstSeed = Seed = StartSeed & (RandomBit * 2 - 1);
for (Pop1 = grp = 0; grp < Groups; grp++)
{
Word_t LowIndex;
Word_t Delta;
Word_t NewSeed;
Delta = Pms[grp].ms_delta;
// Test J1S, JLI
NewSeed = TestJudyIns(&J1, &JL, &JH, Seed, Delta);
// Accumulate the Total population of arrays
Pop1 += Delta;
Meas = Pop1;
// Only test the maximum of TValues if not zero
if (TValues)
Meas = (Pop1 < TValues) ? Pop1 : TValues;
printf("%10lu %9lu", Pop1, Meas);
printf(" %6.3f", DeltaUSec1);
printf(" %6.3f", DeltaUSecL);
printf(" %6.3f", DeltaUSecHS);
( run in 2.184 seconds using v1.01-cache-2.11-cpan-cdf2f3d4e48 )