Alien-Judy

 view release on metacpan or  search on metacpan

src/judy-1.0.5/test/Judy1LTime.c  view on Meta::CPAN

    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 // _TIMEIT_H

//=======================================================================
//      M E M O R Y   S I Z E   M A C R O S
//=======================================================================
//      Most mallocs have mallinfo()
//      However, the size is an int, so just about worthless in 64 bit
//      machines with more than 4Gb ram.  But needed on 32 bit machines 
//      that have more than a 1Gbyte of memory, because malloc stops
//      using sbrk() about at that time (runs out of heap -- use mmap()).

// un-define this if your malloc has mallinfo(); see above

#define NOMALLINFO 1

double    DeltaMem;

#ifndef NOMALLINFO

#include <malloc.h>             // mallinfo()

struct mallinfo malStart;

#define STARTmem malStart = mallinfo() /* works with some mallocs */
#define ENDmem                                                  \
{                                                               \
    struct mallinfo malEnd = mallinfo();                        \
/* strange little dance from signed to unsigned to double */    \
    unsigned int _un_int = malEnd.arena - malStart.arena;       \
    DeltaMem = _un_int;      /* to double */                    \
}

#else // MALLINFO

// this usually works for machines with less than 1-2Gb RAM.
// (it does not include memory ACQUIRED by mmap())

char     *malStart;

#define STARTmem (malStart = (char *)sbrk(0))
#define ENDmem                                                  \
{                                                               \
    char  *malEnd =  (char *)sbrk(0);                           \
    DeltaMem = malEnd - malStart;                               \
}

#endif // MALLINFO

//=======================================================================

// Common macro to handle a failure
#define FAILURE(STR, UL)                                                \
{                                                                       \
printf(         "Error: %s %lu, file='%s', 'function='%s', line %d\n",  \
        STR, UL, __FILE__, __FUNCTI0N__, __LINE__);                     \
fprintf(stderr, "Error: %s %lu, file='%s', 'function='%s', line %d\n",  \
        STR, UL, __FILE__, __FUNCTI0N__, __LINE__);                     \
        exit(1);                                                        \
}

// Interations without improvement
//  Minimum of 2 loops, maximum of 1000000
#define MINLOOPS 2
#define MAXLOOPS 1000000

// Maximum or 10 loops with no improvement
#define ICNT 10

// Structure to keep track of times
typedef struct MEASUREMENTS_STRUCT
{
    Word_t    ms_delta;
}
ms_t     , *Pms_t;

// Specify prototypes for each test routine
int       NextNumb(Word_t *PNumber, double *PDNumb, double DMult,
                   Word_t MaxN);

Word_t    TestJudyIns(void **J1, void **JL, Word_t Seed, Word_t Elems);

Word_t    TestJudyDup(void **J1, void **JL, Word_t Seed, Word_t Elems);

int       TestJudyDel(void **J1, void **JL, Word_t Seed, Word_t Elems);

Word_t    TestJudyGet(void *J1, void *JL, Word_t Seed, Word_t Elems);

int       TestJudyCount(void *J1, void *JL, Word_t LowIndex, Word_t Elems);

Word_t    TestJudyNext(void *J1, void *JL, Word_t LowIndex, Word_t Elems);

int       TestJudyPrev(void *J1, void *JL, Word_t HighIndex, Word_t Elems);

Word_t    TestJudyNextEmpty(void *J1, void *JL, Word_t LowIndex,
                            Word_t Elems);

Word_t    TestJudyPrevEmpty(void *J1, void *JL, Word_t HighIndex,
                            Word_t Elems);

//=======================================================================
// These are LFSF feedback taps for bitwidths of 10..64 sized numbers.
// Tested with Seed=0xc1fc to 35 billion numbers
//=======================================================================

Word_t    StartSeed = 0xc1fc;   // default beginning number
Word_t    FirstSeed;

Word_t    MagicList[] = {
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0..9
    0x27f,                      // 10
    0x27f,                      // 11
    0x27f,                      // 12
    0x27f,                      // 13
    0x27f,                      // 14
    0x27f,                      // 15
    0x1e71,                     // 16



( run in 0.597 second using v1.01-cache-2.11-cpan-817d5f8af8b )