Alien-Judy
view release on metacpan or search on metacpan
src/judy-1.0.5/test/StringCompare.c view on Meta::CPAN
#define STARTTm(T) gettimeofday(&__TVBeg_##T, NULL)
#define ENDTm(D,T) \
{ \
gettimeofday(&__TVEnd_##T, NULL); \
(D) = (double)(__TVEnd_##T.tv_sec - __TVBeg_##T.tv_sec) * 1E6 + \
((double)(__TVEnd_##T.tv_usec - __TVBeg_##T.tv_usec)); \
}
#endif // ! CPUMHZ
//=======================================================================
// M E M O R Y S I Z E M A C R O S
//=======================================================================
// use mallinfo() instead of sbrk() for memory usage measurements
// this should include the RAM that was mmap()ed in malloc()
static Word_t DeltaMem; // for remembering
// Some mallocs have mallinfo()
// #define MALLINFO 1
#ifdef MALLINFO
#include <malloc.h> // mallinfo()
static struct mallinfo malStart;
#define STARTmem malStart = mallinfo()
#define ENDmem(DELTAMEM) \
{ \
struct mallinfo malEnd = mallinfo(); \
/* strange little dance from signed to unsigned to double */ \
unsigned int _un_int = malEnd.arena - malStart.arena; \
(DELTAMEM) = (double)_un_int; /* to double */ \
}
#else // NO MALLINFO
// this usually works for machines with less than 1-2Gb RAM.
// (it does NOT include memory ACQUIRED by mmap())
static char *malStart;
#define STARTmem (malStart = (char *)sbrk(0))
#define ENDmem(DELTAMEM) \
{ \
char *malEnd = (char *)sbrk(0); \
(DELTAMEM) = (double)(malEnd - malStart); \
}
#endif // NO MALLINFO
//=======================================================================
// F I L E O P E N and M A L L O C F A I L M A C R O S
//=======================================================================
#define FILERROR \
{ \
printf("\n !! OOps - Open file error \"%s\": %s (errno = %d)\n", \
argv[fileidx], strerror(errno), errno); \
fprintf(stderr, " OOps - Open file error \"%s\": %s (errno = %d)\n",\
argv[fileidx], strerror(errno), errno); \
exit(1); \
}
#define MALLOCERROR \
{ \
printf("\n !! OOps - malloc failed at Line = %d\n", __LINE__); \
fprintf(stderr, " OOps - malloc failed at Line = %d\n", __LINE__); \
exit(1); \
}
//=======================================================================
// This alternate form of JudyMalloc() is used to keep track how much ram is
// used on some of the below ADT's
//=======================================================================
// JUDY INCLUDE FILES
//#include "Judy.h"
// ****************************************************************************
// 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.
static Word_t TotalJudyMalloc = 0;
Word_t
JudyMalloc(Word_t Words)
{
Word_t Addr;
Addr = (Word_t)malloc(Words * sizeof(Word_t));
if (Addr)
TotalJudyMalloc += Words;
return (Addr);
} // JudyMalloc()
// ****************************************************************************
// J U D Y F R E E
void
JudyFree(void *PWord, Word_t Words)
{
free(PWord);
assert((long)(TotalJudyMalloc - Words) >= 0L);
TotalJudyMalloc -= Words;
} // JudyFree()
// ****************************************************************************
// J U D Y M A L L O C
//
// Higher-level "wrapper" for allocating objects that need not be in RAM,
// although at this time they are in fact only in RAM. Later we hope that some
// entire subtrees (at a JPM or branch) can be "virtual", so their allocations
// and frees should go through this level.
Word_t
JudyMallocVirtual(Word_t Words)
{
return (JudyMalloc(Words));
} // JudyMallocVirtual()
( run in 0.660 second using v1.01-cache-2.11-cpan-0c5ce583b80 )