Alien-Judy

 view release on metacpan or  search on metacpan

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



//=======================================================================
//      C O M P I L E D:
//=======================================================================
//
//      cc -static -O3 Judy1LTime.c -lJudy -lm
//
//  the -static is for a little better performace on some platforms
//
//  if optional high-resolution timers are desired:
//
//      cc -static -O3 -DJU_LINUX_IA32 Judy1LTime.c -lJudy -lm
//
//  and read below:
//  
//=======================================================================
//      T I M I N G   M A C R O S
//=======================================================================
// if your machine is one of the supported types in the following header
// file then uncomment this corresponding to what the header file says.

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


double    DeltaUSec;            // Global for remembering delta times

#ifndef _TIMEIT_H

// Note: I have found some Linux systems (2.4.18-6mdk) have bugs in the 
// gettimeofday() routine.  Sometimes the difference of two consective calls 
// returns a negative ~2840 microseconds instead of 0 or 1.  If you use the 
// above #include "timeit.h" and compile with timeit.c and use 
// -DJU_LINUX_IA32, that problem will be eliminated.  This is because for 
// delta times less than .1 sec, the hardware free running timer is used 
// instead of gettimeofday().  I have found the negative time problem
// appears about 40-50 times per second with numerous gettimeofday() calls.
// You should just ignore negative times output.

#define TIMER_vars(T) struct timeval __TVBeg_##T, __TVEnd_##T

#define STARTTm(T) gettimeofday(&__TVBeg_##T, NULL)

#define ENDTm(D,T)                                                      \
{                                                                       \

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

#undef __FUNCTI0N__
#define __FUNCTI0N__ "main"

int
main(int argc, char *argv[])
{
//  Names of Judy Arrays
    void     *J1 = NULL;        // Judy1
    void     *JL = NULL;        // JudyL

    TIMER_vars(tm1);            // declare timer variables
    Word_t    Count1, CountL;
    Word_t    Bytes;

    double    Mult;
    Pms_t     Pms;
    Word_t    Seed;
    Word_t    PtsPdec = 40;     // points per decade
    Word_t    Groups;           // Number of measurement groups
    Word_t    grp;
    Word_t    Pop1;

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

    }
    exit(0);
}

#undef __FUNCTI0N__
#define __FUNCTI0N__ "TestJudyIns"

Word_t
TestJudyIns(void **J1, void **JL, Word_t Seed, Word_t Elements)
{
    TIMER_vars(tm1);            // declare timer variables
    Word_t    TstIndex;
    Word_t    elm;
    Word_t   *PValue;
    Word_t    Seed1 = 0;
    int       Rc;

    double    DDel;
    Word_t    icnt;
    Word_t    lp;
    Word_t    Loops;

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

    }
    return (Seed1);             // New seed
}

#undef __FUNCTI0N__
#define __FUNCTI0N__ "TestJudyDup"

Word_t
TestJudyDup(void **J1, void **JL, Word_t Seed, Word_t Elements)
{
    TIMER_vars(tm1);            // declare timer variables
    Word_t    LowIndex = ~0UL;
    Word_t    TstIndex;
    Word_t    elm;
    Word_t   *PValue;
    Word_t    Seed1;
    int       Rc;

    double    DDel;
    Word_t    icnt;
    Word_t    lp;

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


    return (LowIndex);
}

#undef __FUNCTI0N__
#define __FUNCTI0N__ "TestJudyGet"

Word_t
TestJudyGet(void *J1, void *JL, Word_t Seed, Word_t Elements)
{
    TIMER_vars(tm1);            // declare timer variables
    Word_t    LowIndex = ~0UL;
    Word_t    TstIndex;
    Word_t    elm;
    Word_t   *PValue;
    Word_t    Seed1;
    int       Rc;

    double    DDel;
    Word_t    icnt;
    Word_t    lp;

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


    return (LowIndex);
}

#undef __FUNCTI0N__
#define __FUNCTI0N__ "TestJudyCount"

int
TestJudyCount(void *J1, void *JL, Word_t LowIndex, Word_t Elements)
{
    TIMER_vars(tm1);            // declare timer variables
    Word_t    elm;
    Word_t    Count1, CountL;
    Word_t    TstIndex = LowIndex;
    int       Rc;

    double    DDel;
    Word_t    icnt;
    Word_t    lp;
    Word_t    Loops;

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


    return (0);
}

#undef __FUNCTI0N__
#define __FUNCTI0N__ "TestJudyNext"

Word_t
TestJudyNext(void *J1, void *JL, Word_t LowIndex, Word_t Elements)
{
    TIMER_vars(tm1);            // declare timer variables
    Word_t    elm;

    double    DDel;
    Word_t    icnt;
    Word_t    lp;
    Word_t    Loops;
    Word_t    Jindex;

    Loops = (MAXLOOPS / Elements) + MINLOOPS;

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

//  perhaps a check should be done here -- if I knew what to expect.
    return (Jindex);            // return last one
}

#undef __FUNCTI0N__
#define __FUNCTI0N__ "TestJudyPrev"

int
TestJudyPrev(void *J1, void *JL, Word_t HighIndex, Word_t Elements)
{
    TIMER_vars(tm1);            // declare timer variables
    Word_t    elm;

    double    DDel;
    Word_t    icnt;
    Word_t    lp;
    Word_t    Loops;

    Loops = (MAXLOOPS / Elements) + MINLOOPS;

    if (J1Flag)

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

    return (0);
}

#undef __FUNCTI0N__
#define __FUNCTI0N__ "TestJudyNextEmpty"

// Returns number of consecutive Indexes
Word_t
TestJudyNextEmpty(void *J1, void *JL, Word_t LowIndex, Word_t Elements)
{
    TIMER_vars(tm1);            // declare timer variables
    Word_t    elm;

    double    DDel;
    Word_t    icnt;
    Word_t    lp;
    Word_t    Loops;
    int       Rc;               // Return code

    Loops = (MAXLOOPS / Elements) + MINLOOPS;

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

}

// Routine to time and test JudyPrevEmpty routines

#undef __FUNCTI0N__
#define __FUNCTI0N__ "TestJudyPrevEmpty"

Word_t
TestJudyPrevEmpty(void *J1, void *JL, Word_t HighIndex, Word_t Elements)
{
    TIMER_vars(tm1);            // declare timer variables
    Word_t    elm;

    double    DDel;
    Word_t    icnt;
    Word_t    lp;
    Word_t    Loops;
    int       Rc;

    Loops = (MAXLOOPS / Elements) + MINLOOPS;

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


    return (0);
}

#undef __FUNCTI0N__
#define __FUNCTI0N__ "TestJudyDel"

int
TestJudyDel(void **J1, void **JL, Word_t Seed, Word_t Elements)
{
    TIMER_vars(tm1);            // declare timer variables
    Word_t    TstIndex;
    Word_t    elm;
    Word_t    Seed1;
    int       Rc;

    if (J1Flag)
    {
        STARTTm(tm1);
        for (Seed1 = Seed, elm = 0; elm < Elements; elm++)
        {

src/judy-1.0.5/test/README  view on Meta::CPAN

                information.
JudyMalloc.c    For testing Judy free()s all memory that it malloc()ed.
CheckDupLines.c For the JudyHS manual example
JudyString.c	For the JudyHS manual, but too long

-- The following are obsolete.

Judy1LCheck.c   Program to test functionality of Judy API.        (obsolete)
Judy1LTime.c    Program to time common Judy functions.            (obsolete)
SLcompare.c     Program to compare JudySL performance with others (obsolete)
timeit.c        High resolution timers for certain platforms      (obsolete)
timeit.h        High resolution timers for certain platforms      (obsolete)

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

//#include "timeit.h"

double    DeltaUSec;            // Global for remembering delta times

#ifndef _TIMEIT_H

// Note: I have found some Linux systems (2.4.18-6mdk) to have bugs in the 
// gettimeofday() routine.  Sometimes it returns a negative ~2840 microseconds
// instead of 0 or 1.  If you use the above #include "timeit.h" and compile with
// timeit.c and use -DJU_LINUX_IA32, that problem will be eliminated.  This is
// because for delta times less than .1 sec, the hardware free running timer
// is used instead of gettimeofday().  I have found the negative time problem
// appears about 40-50 times per second with consecutive gettimeofday() calls.

#define TIMER_vars(T) struct timeval __TVBeg_##T, __TVEnd_##T

#define STARTTm(T) gettimeofday(&__TVBeg_##T, NULL)

#define ENDTm(D,T)                                                      \
{                                                                       \
    gettimeofday(&__TVEnd_##T, NULL);                                   \

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

}


//=======================================================================
//      M E A S U R E  A D T   S P E E D  and  M E M O R Y  U S A G E
//=======================================================================

int
main(int argc, char *argv[])
{
    TIMER_vars(tm);             // declare timer variables
    int       fd;               // to read file.
    struct stat statbuf;        // to get size of file
    char     *Pfile;            // ram address of file
    size_t    fsize;            // file size in bytes
    char     *FSmap;            // start address of mapped file
    char     *FEmap;            // end address+1 of mapped file
    char      String[MAXLINE];  // input buffer
    int       StrCnt;           // line counter
    int       ii;               // temp

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

// print command name + run arguments

    printf("# ");
    for (ii = 0; ii < argc; ii++)
        printf("%s ", argv[ii]);
    printf("\n");
    fflush(stdout);

// file is in RAM, read again to measure time

    STARTTm(tm);                // start timer

    for (StrCnt = 0, FSmap = Pfile; FSmap < FEmap; )
    {
        GETLINE(String, FSmap); // 'read' next string

        StrCnt++;
    }
    ENDTm(DeltaUSec, tm);       // end timer
//
//  print header - 6 fields

    printf("#  lines avg_linelen  getline   stored");
    printf(" RAMused/line  store/ln lookup/ln ADT\n");

//  print numb lines  filesize/line

    printf("%8u", StrCnt);      // Number of lines
    printf(" %6.1f byts", (double)fsize / (double)StrCnt); // filesize/line

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

//  print time to read a line

    printf(" %5.3f uS", DeltaUSec / (double)StrCnt);
    fflush(stdout);

// INPUT/STORE LOOP:

// read each input line into String and store into ADT

    STARTmem;                   // current malloc() mem usage
    STARTTm(tm);                // start timer

    for (FSmap = Pfile; FSmap < FEmap; )
    {
        GETLINE(String, FSmap);  // 'read' next string

        STORESTRING(String);
    }
    ENDTm(DeltaUSec, tm);       // end timer
    ENDmem;                     // current malloc() mem usage

//  print number of non-duplicate lines

    printf(" %8u", StrCnt - gDupCnt); // duplicate lines

//  print RAM used by malloc() by ADT to store data

    printf(" %7.1f byts", (double)(DeltaMem + MEMOVD) /
            (double)(StrCnt - gDupCnt));

//  print time per line to store the data

    printf(" %6.3f uS", DeltaUSec / (double)StrCnt);
    fflush(stdout);

// READ BACK LOOP

    STARTTm(tm);                // start timer

    for (FSmap = Pfile; FSmap < FEmap; )
    {
        GETLINE(String, FSmap);  // 'read' next string

        GETSTRING(String);
    }
    ENDTm(DeltaUSec, tm);       // end timer

//  print time per line to lookup the data from the ADT

    printf(" %6.3f uS", DeltaUSec / (double)StrCnt); // store time/line
    printf(" %s\n", ADTMETHOD);

    return (0);                 // done

}                               // main()

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

//      M E A S U R E  A D T   S P E E D  and  M E M O R Y  U S A G E
//=======================================================================

//Word_t    TotalJudyMalloc;

#define         GETSTRING(PCurStr, Strlen)

int
main(int argc, char *argv[])
{
    TIMER_vars(tm);                     // declare timer variables
    FILE     *fid;                      // to read file.
    int       Chr;                      // char read from fgetc
    Pdt_t     Pdt, Pdts;                // array of lengths and pointers to str
    uint8_t  *PCurStr;                  // Current string pointer
    Word_t    LineCnt;                  // line counter
    int       Strlen;                   // = strlen();
    Word_t    StrTot;                   // Total len of strings
    Word_t    StrNumb;                  // current line number
    Word_t    ReadLin;                  // strings to read
    double    Mult;                     // multiplier between groups

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


        printf
            ("# %lu bytes malloc() for 'cached' strings for Get measurement\n",
             Strsiz_);
    }

//=======================================================================
//  TIME GETSTRING() from Cache (most of the time)
//=======================================================================

    STARTTm(tm);                        // start timer
    for (LineCnt = 0; LineCnt < nStrg; LineCnt++)
    {
        GETSTRING(PCurStr, Strlen);
        Strlen = Pdt[LineCnt].dt_strlen;
        PCurStr = Pdt[LineCnt].dt_string;

        if (strlen(PCurStr) != Strlen)  // bring string into Cache
        {
//          necessary to prevent cc from optimizing out
            printf(" !! OOps Bug, wrong string length\n");
            exit(1);
        }
    }
    ENDTm(DeltaUSec, tm);               // end timer

    printf
        ("# Access Time    = %6.3f uS average per string (mostly from Cache)\n",
         DeltaUSec / nStrg);

//=======================================================================
//  TIME GETSTRING() + HASHSTR() from Cache (most of the time)
//=======================================================================

    STARTTm(tm);                        // start timer
    for (LineCnt = 0; LineCnt < nStrg; LineCnt++)
    {
        uint32_t  hval;
        GETSTRING(PCurStr, Strlen);
        PCurStr = Pdt[LineCnt].dt_string;
        Strlen = Pdt[LineCnt].dt_strlen;
        hval = HASHSTR(PCurStr, Strlen, HTblsz);
        if (foolflag)
            printf("OOps foolflag is set, hval = %d\n", hval);
    }
    ENDTm(DeltaUSec, tm);               // end timer

    printf
        ("# HashStr() Time = %6.3f uS average per string (mostly from Cache)\n",
         DeltaUSec / nStrg);

//  randomize the input strings (adjacent strings will not be on same page)

    if (rFlag == 0)
    {
        Randomize(Pdt, nStrg);          // Randomize ALL to be stored

//=======================================================================
//  TIME GETSTRING() from RAM (most of the time)
//=======================================================================

        STARTTm(tm);                    // start timer
        for (LineCnt = 0; LineCnt < nStrg; LineCnt++)
        {
            GETSTRING(PCurStr, Strlen);
            Strlen = Pdt[LineCnt].dt_strlen;
            PCurStr = Pdt[LineCnt].dt_string;

            if (strlen(PCurStr) != Strlen)      // bring string into Cache
            {
//              necessary to prevent cc from optimizing out
                printf(" !! OOps Bug, wrong string length\n");
                exit(1);
            }
        }
        ENDTm(DeltaUSec, tm);           // end timer

        printf
            ("# Access Time    = %6.3f uS average per string (mostly from RAM)\n",
             DeltaUSec / nStrg);

//=======================================================================
//  TIME GETSTRING() + HASHSTR() from RAM (most of the time)
//=======================================================================

        STARTTm(tm);                    // start timer
        for (LineCnt = 0; LineCnt < nStrg; LineCnt++)
        {
            uint32_t  hval;
            GETSTRING(PCurStr, Strlen);
            Strlen = Pdt[LineCnt].dt_strlen;
            PCurStr = Pdt[LineCnt].dt_string;
            hval = HASHSTR(PCurStr, Strlen, HTblsz);
            if (foolflag)
                printf("OOps foolflag is set, hval = %u\n", hval);
        }
        ENDTm(DeltaUSec, tm);           // end timer

        printf
            ("# HashStr() Time = %6.3f uS average per string (mostly from RAM)\n",
             DeltaUSec / nStrg);
    }

//=======================================================================
//  Insert, Get and Delete loops
//=======================================================================

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

        for (grp = 0; grp < Groups; grp++)
        {
            PWord_t   PValue;
            Word_t    Begin = gStored;  // remember current STOREed
            Word_t    Delta = Pms[grp].ms_delta;

            switch (Method)
            {
            case M_Print:
            {
                STARTTm(tm);            // start timer
                for (lines = 0; lines < Delta; lines++, StrNumb++)
                {
                    GETSTRING(PCurStr, Strlen);
                    PCurStr = Pdt[StrNumb].dt_string;
                    Printf("%s\n", (char *)PCurStr);
                }
                ENDTm(DeltaUSec, tm);   // end timer
                break;
            }
            case M_Hash:
            {
                STARTTm(tm);            // start timer
                for (lines = 0; lines < Delta; lines++, StrNumb++)
                {
                    GETSTRING(PCurStr, Strlen);
                    Strlen = Pdt[StrNumb].dt_strlen;
                    PCurStr = Pdt[StrNumb].dt_string;

                    PValue = HashIns(&HRoot, PCurStr, Strlen, HTblsz);
                    if ((*PValue)++ == 0)
                        gStored++;      // number of strings stored
                }
                ENDTm(DeltaUSec, tm);   // end timer
                break;
            }
            case M_JLHash:
            {
                STARTTm(tm);            // start timer
                for (lines = 0; lines < Delta; lines++, StrNumb++)
                {
                    GETSTRING(PCurStr, Strlen);
                    Strlen = Pdt[StrNumb].dt_strlen;
                    PCurStr = Pdt[StrNumb].dt_string;
                    PValue = JLHashIns(&JLHash, PCurStr, Strlen, HTblsz);
                    if ((*PValue)++ == 0)
                        gStored++;      // number of strings stored
                }
                ENDTm(DeltaUSec, tm);   // end timer
                break;
            }
            case M_JudySL:
            {
                STARTTm(tm);            // start timer
                for (lines = 0; lines < Delta; lines++, StrNumb++)
                {
                    GETSTRING(PCurStr, Strlen);
                    PCurStr = Pdt[StrNumb].dt_string;

                    JSLI(PValue, JudySL, PCurStr);      // insert string
                    if ((*PValue)++ == 0)
                        gStored++;      // number of strings stored
                }
                ENDTm(DeltaUSec, tm);   // end timer
                break;
            }
            case M_JudyHS:
            {
                STARTTm(tm);            // start timer
                for (lines = 0; lines < Delta; lines++, StrNumb++)
                {
                    GETSTRING(PCurStr, Strlen);
                    Strlen = Pdt[StrNumb].dt_strlen;
                    PCurStr = Pdt[StrNumb].dt_string;

                    JHSI(PValue, JudyHS, PCurStr, Strlen);      // insert string
                    if ((*PValue)++ == 0)
                        gStored++;      // number of strings stored
                }
                ENDTm(DeltaUSec, tm);   // end timer
                break;
            }

// NOTE:  the ADT's below here are so slow, that I did not add much effort 
// to clean them up. (dlb)

            case M_Splay:
            {
                STARTTm(tm);            // start timer
                for (lines = 0; lines < Delta; lines++, StrNumb++)
                {
                    GETSTRING(PCurStr, Strlen);
                    PCurStr = Pdt[StrNumb].dt_string;

                    splayinsert(&spans, (char *)PCurStr);
                }
                ENDTm(DeltaUSec, tm);   // end timer
                break;
            }
            case M_Redblack:
            {
                STARTTm(tm);            // start timer
                for (lines = 0; lines < Delta; lines++, StrNumb++)
                {
                    GETSTRING(PCurStr, Strlen);
                    PCurStr = Pdt[StrNumb].dt_string;

                    redblackinsert(&rbans, (char *)PCurStr);
                }
                ENDTm(DeltaUSec, tm);   // end timer
                break;
            }
            case M_Ternary:
            {
                STARTTm(tm);            // start timer
                for (lines = 0; lines < Delta; lines++, StrNumb++)
                {
                    GETSTRING(PCurStr, Strlen);
                    Strlen = Pdt[StrNumb].dt_strlen;
                    PCurStr = Pdt[StrNumb].dt_string;

                    TernaryIns(&Ternary, PCurStr, Strlen);
                }
                ENDTm(DeltaUSec, tm);   // end timer
                break;
            }
            default:
                assert(0);              // cant happen
                break;
            }
            ENDmem(DeltaMem);           // current malloc() mem usage

            ReadLin = StrNumb;          // adjust delta
            if (ReadLin > TValues)

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

//                  Allocate and make sequencial string buffer
                    Pdts = BuildSeqBuf(Pdt, ReadLin);
                }
            }
            switch (Method)
            {
            case M_Print:
                break;
            case M_Hash:
            {
                STARTTm(tm);            // start timer
                for (lines = 0; lines < ReadLin; lines++)
                {
                    GETSTRING(PCurStr, Strlen);
                    Strlen = Pdts[lines].dt_strlen;
                    PCurStr = Pdts[lines].dt_string;

                    PValue = HashGet(HRoot, PCurStr, Strlen);   // get string
                    assert(PValue != NULL);
                    assert(*PValue > 0);
                }
                ENDTm(DeltaUSec, tm);   // end timer
                break;
            }
            case M_JLHash:
            {
                STARTTm(tm);            // start timer
                for (lines = 0; lines < ReadLin; lines++)
                {
                    GETSTRING(PCurStr, Strlen);
                    Strlen = Pdts[lines].dt_strlen;
                    PCurStr = Pdts[lines].dt_string;

                    PValue = JLHashGet(JLHash, PCurStr, Strlen);        // get string
                    assert(PValue != NULL);
                    assert(*PValue > 0);
                }
                ENDTm(DeltaUSec, tm);   // end timer
                break;
            }
            case M_JudySL:
            {
                STARTTm(tm);            // start timer
                for (lines = 0; lines < ReadLin; lines++)
                {
                    GETSTRING(PCurStr, Strlen);
                    PCurStr = Pdts[lines].dt_string;

                    JSLG(PValue, JudySL, PCurStr);      // get string
                    assert(PValue != NULL);
                    assert(*PValue > 0);
                }
                ENDTm(DeltaUSec, tm);   // end timer
                break;
            }
            case M_JudyHS:
            {
                STARTTm(tm);            // start timer
                for (lines = 0; lines < ReadLin; lines++)
                {
                    GETSTRING(PCurStr, Strlen);
                    Strlen = Pdts[lines].dt_strlen;
                    PCurStr = Pdts[lines].dt_string;

                    JHSG(PValue, JudyHS, PCurStr, Strlen);      // get string
                    assert(PValue != NULL);
                    assert(*PValue > 0);
                }
                ENDTm(DeltaUSec, tm);   // end timer
                break;
            }

// NOTE:  the ADT's below here are so slow, that I did not add much effort 
// to clean them up. (dlb)

            case M_Splay:
            {
                STARTTm(tm);            // start timer
                for (lines = 0; lines < ReadLin; lines++)
                {
                    GETSTRING(PCurStr, Strlen);
                    PCurStr = Pdts[lines].dt_string;

                    splaysearch(&spans, (char *)PCurStr);
                }
                ENDTm(DeltaUSec, tm);   // end timer
                break;
            }
            case M_Redblack:
            {
                STARTTm(tm);            // start timer
                for (lines = 0; lines < ReadLin; lines++)
                {
                    GETSTRING(PCurStr, Strlen);
                    PCurStr = Pdts[lines].dt_string;

                    redblacksearch(&rbans, (char *)PCurStr);
                }
                ENDTm(DeltaUSec, tm);   // end timer
                break;
            }
            case M_Ternary:
            {
                STARTTm(tm);            // start timer
                for (lines = 0; lines < ReadLin; lines++)
                {
                    GETSTRING(PCurStr, Strlen);
                    Strlen = Pdts[lines].dt_strlen;
                    PCurStr = Pdts[lines].dt_string;

                    if (TernaryGet(Ternary, PCurStr, Strlen) == 0)
                    {
                        printf("\n OOps - Ternary Bug at Line = %d\n",
                               __LINE__);
                        exit(1);
                    }
                }
                ENDTm(DeltaUSec, tm);   // end timer
                break;
            }
            default:
                assert(0);              // cant happen
                break;
            }
            Mult = DeltaUSec / (double)ReadLin;

//          save least value
            if (Mult < Pms[grp].ms_minretrive)

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

        {
            Randomize(Pdt, StrNumb);    // Randomize ONLY those stored
        }
        switch (Method)
        {
        case M_JudySL:
        {
            if (DFlag)
            {
                Printf("# Begin JudySLDel() loop...\n");
                STARTTm(tm);            // start timer
                for (lines = 0; lines < nStrg; lines++)
                {
                    int       Rc;
                    GETSTRING(PCurStr, Strlen);
                    PCurStr = Pdt[lines].dt_string;
                    JSLD(Rc, JudySL, PCurStr);  // delete string
                    assert(Rc != JERR);
                }
                ENDTm(DeltaUSec, tm);   // end timer
            }
            else
            {
                Printf("# Begin JudySLFreeArray()...\n");
                STARTTm(tm);            // start timer
                JSLFA(Bytes, JudySL);
                ENDTm(DeltaUSec, tm);   // end timer
            }
            break;
        }
        case M_JudyHS:
        {
            if (DFlag)
            {
                int       Rc;
                Printf("# Begin JudyHSDel() loop...");
                STARTTm(tm);            // start timer
                for (lines = 0; lines < nStrg; lines++)
                {
                    GETSTRING(PCurStr, Strlen);
                    Strlen = Pdt[lines].dt_strlen;
                    PCurStr = Pdt[lines].dt_string;
                    JHSD(Rc, JudyHS, PCurStr, Strlen);  // Delete string
                    assert(Rc != JERR);
                }
                ENDTm(DeltaUSec, tm);   // end timer
            }
            else
            {
                Printf("# Begin JudyHSFreeArray()...\n");
                STARTTm(tm);            // start timer
                JHSFA(Bytes, JudyHS);
                ENDTm(DeltaUSec, tm);   // end timer
            }
            break;
        }
        case M_Hash:
        {
            if (DFlag)
            {
                Printf("# Begin HashDel() loop...\n");
                STARTTm(tm);            // start timer
                for (lines = 0; lines < nStrg; lines++)
                {
                    GETSTRING(PCurStr, Strlen);
                    Strlen = Pdt[lines].dt_strlen;
                    PCurStr = Pdt[lines].dt_string;
                    HashDel(&HRoot, PCurStr, Strlen);   // Delete string
                }
                ENDTm(DeltaUSec, tm);   // end timer
            }
            else
            {
                Printf("# Begin HashFreeArray()...\n");
                STARTTm(tm);            // start timer
                Bytes = HashFreeArray(&HRoot);
                ENDTm(DeltaUSec, tm);   // end timer
            }
            break;
        }
        case M_JLHash:
        {
            if (DFlag)
            {
                Printf("# Begin JLHashDel() loop...\n");
                STARTTm(tm);            // start timer
                for (lines = 0; lines < nStrg; lines++)
                {
                    GETSTRING(PCurStr, Strlen);
                    Strlen = Pdt[lines].dt_strlen;
                    PCurStr = Pdt[lines].dt_string;
                    JLHashDel(&JLHash, PCurStr, Strlen);        // Delete string
                }
                ENDTm(DeltaUSec, tm);   // end timer
            }
            else
            {
                Printf("# Begin JLHashFreeArray()...\n");
                STARTTm(tm);            // start timer
                Bytes = JLHashFreeArray(&JLHash);
                ENDTm(DeltaUSec, tm);   // end timer
            }
            break;
        }
        default:
            printf("# Delete not implemented yet, so quit\n");
            Passes = 1;                 // No, delete, so quit
            break;
        }
//  average time per line to delete (including duplicate strings)
        if (Bytes)                      // Measured freed bytes?

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

#include <unistd.h>		// for getopt(), which Win32 lacks.
#include <time.h>
#include "timeit.h"

double USecPerClock;	// usec per control register count.


// ****************************************************************************
// F I N D   C P U   S P E E D
//
// Return microseconds per control/timer register count.  Examples:
//
// 0.002 for 500 MHz processor
// 0.001 for 1 GHz processor

double find_CPU_speed(void)
{
	double DeltaUSec;	// Timing result in uSec.
	TIMER_vars(tm);		// creates __TVBeg_tm, ...
				// (used for consistency with __START_HRTm)

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

//
//   cc -Wl,-a,archive -DJU_HPUX_PA -D__HPUX__ -D_TIMEIT_TEST -o timeit timeit.c
//   timeit			# run test program.
//   rm -f timeit		# clean up after test.

int main(int argc, char **argv)
{
	int     i = 0;		// loop index.
	long    i_max = 10;	// number of loops.
	int     preload = 1;	// loops to throw away (preload cache).
	double  ztime;		// timer overhead.
	double  usec[4];	// for early timing tests.
	double  DeltaUSec;	// timing result in usec.
	double  prevtime;	// from previous loop.
	double  mintime;	// minimum event time.
	struct timeval tmjunk;	// for throw-away syscall.
	TIMER_vars(tm1);	// overall timer variables.
	TIMER_vars(tm2);	// misc + loop timer variables.


// INITIALIZE:

	STARTTm(tm1);		// whole program timer.

	i_max += preload;

// The first arg is the number of iterations (default is i_max):

	if (argc > 1)
	{
	    i = atoi(argv[1]) + preload;
	    if (i > 0) i_max = (long)i;
	}

// Calculate timer overhead (ztime):

#ifdef _TIMEIT_HIGHRES
	(void) puts("Possible slight delay here due to find_CPU_speed()...");
#else
	(void) puts("No high-res clock or find_CPU_speed() for this platform.");
#endif

	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.

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


// 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);

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



// 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)
	    {
		if (mintime == MAXDOUBLE) mintime = DeltaUSec;

		(void) printf("%3d. %8.3f usec,\tmintime diff %8.1f %%\n",
			      i - preload, DeltaUSec,
			      ((DeltaUSec - mintime) * 100) / mintime);

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



// TIME SOMETHING SLOW:

	(void) puts("\nTiming something slow: \"sleep(1)\":");
	mintime = MAXDOUBLE;

	for (i = 1; i <= i_max; ++i)
	{
	    prevtime = DeltaUSec;
	    STARTTm(tm2);		// start the timer.
	    sleep(1);
	    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 sec,\tmintime diff %8.1f %%\n",
			      i - preload, DeltaUSec/1E6,
			      ((DeltaUSec - mintime) * 100) / mintime);

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



( run in 1.092 second using v1.01-cache-2.11-cpan-49f99fa48dc )