Alien-Judy
view release on metacpan or search on metacpan
src/judy-1.0.5/test/StringCompare.c view on Meta::CPAN
{
if (*s < p->splitchar)
p = p->lokid;
else if (*s == p->splitchar)
{
if (*s++ == 0)
return 1;
p = p->eqkid;
}
else
p = p->hikid;
}
return 0;
}
//=======================================================================
// 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
Word_t Groups; // number of measurement groups
Word_t grp; // current group
Pvoid_t JudySL = NULL; // JudySL root pointer
Pvoid_t JudyHS = NULL; // JudyHS root pointer
Pvoid_t JLHash = NULL; // JLHash root pointer
Phinfo_t HRoot = NULL; // hash table root pointer
Tptr Ternary = { 0 }; // Ternary struct root pointer
Method_t Method = M_invalid; // the method to measure
Word_t lines = 0; // to shut up compiler
Word_t Bytes = 0; // Bytes deallocated from FreeArray
Word_t StringMemory; // Bytes allocated for input data
int Pass;
int Passes = 1;
int Opt;
extern char *optarg;
int ErrorFlag = 0;
// un-buffer output
setbuf(stdout, NULL);
//============================================================
// PARSE INPUT PARAMETERS
//============================================================
while ((Opt = getopt(argc, argv, "A:H:L:n:T:P:M:praDC")) != -1)
{
switch (Opt)
{
case 'A':
if (Method != M_invalid)
{
printf("\nOnly ONE '-A<ADT>' is allowed!!!!!!\n");
ErrorFlag++;
break;
}
if (strcmp(optarg, "Print") == 0)
Method = M_Print;
if (strcmp(optarg, "Hash") == 0)
{
Method = M_Hash;
HTblsz = 1LU << 20; // default 1.0+ million
}
if (strcmp(optarg, "JLHash") == 0)
{
Method = M_JLHash;
HTblsz = 0; // max 2^32
}
if (strcmp(optarg, "JudySL") == 0)
Method = M_JudySL;
if (strcmp(optarg, "Splay") == 0)
Method = M_Splay;
if (strcmp(optarg, "Redblack") == 0)
Method = M_Redblack;
if (strcmp(optarg, "JudyHS") == 0)
Method = M_JudyHS;
if (strcmp(optarg, "Ternary") == 0)
Method = M_Ternary;
break;
case 'H': // Size of Hash table
HTblsz = strtoul(optarg, NULL, 0);
break;
case 'L': // Number of Loops
Passes = atoi(optarg);
if (Passes <= 0)
{
printf("\n !! OOps - Number of Loops must be > 0\n");
ErrorFlag++;
}
break;
case 'n': // Max population of arrays
nStrg = strtoul(optarg, NULL, 0); // Size of Linear Array
if (nStrg == 0)
{
printf("\n !! OOps - Number of strings must be > 0\n");
ErrorFlag++;
}
break;
case 'T': // Maximum retrieve tests for timing
src/judy-1.0.5/test/StringCompare.c view on Meta::CPAN
printf(" -A Redblack");
break;
case M_Ternary:
printf(" -A Ternary");
break;
default:
break;
}
if (HTblsz)
printf(" -H%lu", HTblsz);
printf(" -P%lu", PtsPdec);
printf(" -L%d", Passes);
if (pFlag)
printf(" -p");
if (rFlag)
printf(" -r");
if (DFlag)
printf(" -D");
if (CFlag)
printf(" -C");
printf(" -M%d", MLength);
printf(" %s", argv[fileidx]);
printf("\n");
// print some header
printf("# This file is in a format to input to 'jbgraph'\n");
printf("# XLABEL Stored\n");
printf("# YLABEL Microseconds / Index\n");
printf("# COLHEAD 1 Total Insert attempts\n");
printf("# COLHEAD 2 Number Gets\n");
printf("# COLHEAD 3 Duplicate strings\n");
printf("# COLHEAD 4 Insert Time (uS)\n");
printf("# COLHEAD 5 Get Time (uS)\n");
printf("# COLHEAD 6 Hash Chain Length\n");
printf("# COLHEAD 7 Average RAM/String\n");
// uname(2) strings describing the machine
{
struct utsname ubuf; // for system name
if (uname(&ubuf) == -1)
printf("# Uname(2) failed\n");
else
printf("# %s %s %s %s %s\n", ubuf.sysname, ubuf.nodename,
ubuf.release, ubuf.version, ubuf.machine);
}
if (sizeof(Word_t) == 8)
printf("# 64 Bit CPU\n");
else if (sizeof(Word_t) == 4)
printf("# 32 Bit CPU\n");
#ifdef CPUMHZ
printf("# Processor speed compiled at %d Mhz\n", CPUMHZ);
#endif // CPUMHZ
if (Method == M_Hash)
printf("# Hash record struct: sizeof(hrec_t) = %d\n", sizeof(hrec_t));
if (Method == M_Ternary)
printf("# Ternary record struct: sizeof(Tnode) = %d\n", sizeof(Tnode));
// OPEN INPUT FILE:
if ((fid = fopen(argv[fileidx], "r")) == NULL)
FILERROR;
for (StrTot = Strlen = LineCnt = 0; (Chr = fgetc(fid)) != EOF;)
{
if (Chr == '\n')
{
if (Strlen) // eat zero length lines
{
if (Strlen > MLength)
Strlen = MLength;
LineCnt++; // increase string count
Strlen++; // add a \0 for JudySL
if (aFlag) // for word alignment
StrTot += ROUNDUPWORD(Strlen);
else
StrTot += Strlen; // memory needed to store strings
if (LineCnt == nStrg) // shorten if required by -n option
break;
Strlen = 0;
}
}
else
{
Strlen++;
}
}
fclose(fid);
fid = NULL;
nStrg = LineCnt; // adj if necessary
// get struct to keep track of the strings
StringMemory = sizeof(dt_t) * nStrg;
Pdt = (Pdt_t) malloc(sizeof(dt_t) * nStrg);
if (Pdt == NULL)
MALLOCERROR;
// get memory to store the strings
StringMemory += StrTot;
PCurStr = (uint8_t *) malloc(StrTot);
if (PCurStr == NULL)
MALLOCERROR;
// BRING FILE INTO RAM, COUNT LINES and CHECK LENGTH
//============================================================
// CALCULATE NUMBER OF MEASUREMENT GROUPS -- points per decade
//============================================================
// Calculate Multiplier for number of points per decade
Mult = pow(10.0, 1.0 / (double)PtsPdec);
{
double sum;
Word_t numb, prevnumb;
// Count number of measurements needed (10K max)
( run in 1.193 second using v1.01-cache-2.11-cpan-13bb782fe5a )