"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test/testhashtable.cpp" between
muscle8.20.zip and muscle8.30.zip

About: MUSCLE (Multi User Server Client Linking Environment) is a messaging server and networking API. The included server program ("muscled") lets its clients message each other, and/or store information in its serverside hierarchical database.

testhashtable.cpp  (muscle8.20):testhashtable.cpp  (muscle8.30)
skipping to change at line 349 skipping to change at line 349
double itemsPerSecond = ((double)numItems*((double)MICROS_PER_SECOND))/elapse d; double itemsPerSecond = ((double)numItems*((double)MICROS_PER_SECOND))/elapse d;
printf(" It took " UINT64_FORMAT_SPEC " microseconds to %s " UINT32_FORMAT_ SPEC " items, so we %s %.0f items per second\n", elapsed, verb, numItems, verb, itemsPerSecond); printf(" It took " UINT64_FORMAT_SPEC " microseconds to %s " UINT32_FORMAT_ SPEC " items, so we %s %.0f items per second\n", elapsed, verb, numItems, verb, itemsPerSecond);
*(tallies.GetOrPut(verb)) += itemsPerSecond; *(tallies.GetOrPut(verb)) += itemsPerSecond;
} }
// This program exercises the Hashtable class. // This program exercises the Hashtable class.
int main(int argc, char ** argv) int main(int argc, char ** argv)
{ {
CompleteSetupSystem css; CompleteSetupSystem css;
Message temp; if (ParseArgs(argc, argv, temp).IsOK()) HandleStandardDaemonArg s(temp); Message tempMsg; if (ParseArgs(argc, argv, tempMsg).IsOK()) HandleStandardDae monArgs(tempMsg);
if (temp.HasName("inter")) return DoInteractiveTest(); if (tempMsg.HasName("inter")) return DoInteractiveTest();
// Make sure that setting equal to an empty Hashtable clears the buffer (FogB ugz #10274) // Make sure that setting equal to an empty Hashtable clears the buffer (FogB ugz #10274)
{ {
Hashtable<String,String> table; Hashtable<String,String> table;
for (int32 i=0; i<1000; i++) table.Put(String("xxx%1").Arg(i), "foo"); for (int32 i=0; i<1000; i++) table.Put(String("xxx%1").Arg(i), "foo");
printf("After population of " UINT32_FORMAT_SPEC " items, table size is " UINT32_FORMAT_SPEC "\n", table.GetNumItems(), table.GetNumAllocatedItemSlots()); printf("After population of " UINT32_FORMAT_SPEC " items, table size is " UINT32_FORMAT_SPEC "\n", table.GetNumItems(), table.GetNumAllocatedItemSlots());
if (table.ShrinkToFit().IsOK()) printf("After shrink-to-fit, table allocat ion is " UINT32_FORMAT_SPEC " for " UINT32_FORMAT_SPEC " items\n", table.GetNumA llocatedItemSlots(), table.GetNumItems()); if (table.ShrinkToFit().IsOK()) printf("After shrink-to-fit, table allocat ion is " UINT32_FORMAT_SPEC " for " UINT32_FORMAT_SPEC " items\n", table.GetNumA llocatedItemSlots(), table.GetNumItems());
else printf("Shrink-to-fit failed!?\n"); else printf("Shrink-to-fit failed!?\n");
skipping to change at line 568 skipping to change at line 568
} }
Hashtable<uint32, const char *> sillyTable; Hashtable<uint32, const char *> sillyTable;
sillyTable.Put(15, "Fifteen"); sillyTable.Put(15, "Fifteen");
sillyTable.Put(100, "One Hundred"); sillyTable.Put(100, "One Hundred");
sillyTable.Put(150, "One Hundred and Fifty"); sillyTable.Put(150, "One Hundred and Fifty");
sillyTable.Put(200, "Two Hundred"); sillyTable.Put(200, "Two Hundred");
sillyTable.Put((uint32)-1, "2^32 - 1!"); sillyTable.Put((uint32)-1, "2^32 - 1!");
if (sillyTable.ContainsKey((uint32)-1) == false) bomb("large value failed! "); if (sillyTable.ContainsKey((uint32)-1) == false) bomb("large value failed! ");
const char * temp = NULL; const char * tempStr = NULL;
sillyTable.Get(100, temp); sillyTable.Get(100, tempStr);
sillyTable.Get(101, temp); // will fail sillyTable.Get(101, tempStr); // will fail
printf("100 -> %s\n",temp); printf("100 -> %s\n", tempStr);
printf("Entries in sillyTable:\n"); printf("Entries in sillyTable:\n");
for (HashtableIterator<uint32, const char *> it(sillyTable); it.HasData(); it++) for (HashtableIterator<uint32, const char *> it(sillyTable); it.HasData(); it++)
{ {
const char * nextValue = NULL; const char * nextValue = NULL;
status_t ret = sillyTable.Get(it.GetKey(), nextValue); status_t ret = sillyTable.Get(it.GetKey(), nextValue);
printf("%i %s: " UINT32_FORMAT_SPEC " -> %s\n", it.HasData(), ret(), it .GetKey(), nextValue); printf("%i %s: " UINT32_FORMAT_SPEC " -> %s\n", it.HasData(), ret(), it .GetKey(), nextValue);
} }
} }
table.Clear(); table.Clear();
{ {
const uint32 NUM_ITEMS = 1000000; const uint32 NUM_ITEMS = 1000000;
const uint32 NUM_RUNS = 3; const uint32 NUM_RUNS = 3;
Hashtable<int, int> testCopy; Hashtable<int, int> testCopy;
Hashtable<String, double> tallies; Hashtable<String, double> tallies;
for (uint32 t=0; t<NUM_RUNS; t++) for (uint32 t=0; t<NUM_RUNS; t++)
{ {
Hashtable<int, int> table; (void) table.EnsureSize(NUM_ITEMS); Hashtable<int, int> iTable; (void) iTable.EnsureSize(NUM_ITEMS);
printf("SORT SPEED TEST ROUND " UINT32_FORMAT_SPEC "/" UINT32_FORMAT_SP EC ":\n", t+1, NUM_RUNS); printf("SORT SPEED TEST ROUND " UINT32_FORMAT_SPEC "/" UINT32_FORMAT_SP EC ":\n", t+1, NUM_RUNS);
uint64 startTime = GetRunTime64(); uint64 startTime = GetRunTime64();
srand(0); for (uint32 i=0; i<NUM_ITEMS; i++) table.Put(rand(), rand()); // we want this to be repeatable, hence srand(0) srand(0); for (uint32 i=0; i<NUM_ITEMS; i++) iTable.Put(rand(), rand()) ; // we want this to be repeatable, hence srand(0)
AddTally(tallies, "place", startTime, NUM_ITEMS); AddTally(tallies, "place", startTime, NUM_ITEMS);
startTime = GetRunTime64(); startTime = GetRunTime64();
table.SortByValue(); iTable.SortByValue();
AddTally(tallies, "sort", startTime, NUM_ITEMS); AddTally(tallies, "sort", startTime, NUM_ITEMS);
startTime = GetRunTime64(); startTime = GetRunTime64();
testCopy = table; // just to make sure copying a table works testCopy = iTable; // just to make sure copying a table works
AddTally(tallies, "copy", startTime, NUM_ITEMS); AddTally(tallies, "copy", startTime, NUM_ITEMS);
startTime = GetRunTime64(); startTime = GetRunTime64();
if (testCopy != table) bomb("Copy was not the same!"); if (testCopy != iTable) bomb("Copy was not the same!");
AddTally(tallies, "compare", startTime, NUM_ITEMS); AddTally(tallies, "compare", startTime, NUM_ITEMS);
startTime = GetRunTime64(); startTime = GetRunTime64();
if (testCopy.IsEqualTo(table, true) == false) bomb("Copy was not the sa me, considering ordering!"); if (testCopy.IsEqualTo(iTable, true) == false) bomb("Copy was not the s ame, considering ordering!");
AddTally(tallies, "o-compare", startTime, NUM_ITEMS); AddTally(tallies, "o-compare", startTime, NUM_ITEMS);
startTime = GetRunTime64(); startTime = GetRunTime64();
table.Clear(); iTable.Clear();
AddTally(tallies, "clear", startTime, NUM_ITEMS); AddTally(tallies, "clear", startTime, NUM_ITEMS);
} }
printf("GRAND AVERAGES OVER ALL " UINT32_FORMAT_SPEC " RUNS ARE:\n", NUM_R UNS); printf("GRAND AVERAGES OVER ALL " UINT32_FORMAT_SPEC " RUNS ARE:\n", NUM_R UNS);
for (HashtableIterator<String, double> iter(tallies); iter.HasData(); iter ++) printf(" %f items/second for %s\n", iter.GetValue()/NUM_RUNS, iter.GetKey( )()); for (HashtableIterator<String, double> iter(tallies); iter.HasData(); iter ++) printf(" %f items/second for %s\n", iter.GetValue()/NUM_RUNS, iter.GetKey( )());
} }
// Now some timing test with String keys and values, for testing of the C++11 move semantics // Now some timing test with String keys and values, for testing of the C++11 move semantics
PrintAndClearStringCopyCounts("Before String Sort test"); PrintAndClearStringCopyCounts("Before String Sort test");
{ {
const uint32 NUM_ITEMS = 1000000; const uint32 NUM_ITEMS = 1000000;
const uint32 NUM_RUNS = 3; const uint32 NUM_RUNS = 3;
Hashtable<String, String> testCopy; Hashtable<String, String> testCopy;
Hashtable<String, double> tallies; Hashtable<String, double> tallies;
for (uint32 t=0; t<NUM_RUNS; t++) for (uint32 t=0; t<NUM_RUNS; t++)
{ {
Hashtable<String, String> table; (void) table.EnsureSize(NUM_ITEMS); Hashtable<String, String> sTable; (void) sTable.EnsureSize(NUM_ITEMS);
printf("STRING SORT SPEED TEST ROUND " UINT32_FORMAT_SPEC "/" UINT32_FO RMAT_SPEC ":\n", t+1, NUM_RUNS); printf("STRING SORT SPEED TEST ROUND " UINT32_FORMAT_SPEC "/" UINT32_FO RMAT_SPEC ":\n", t+1, NUM_RUNS);
uint64 startTime = GetRunTime64(); uint64 startTime = GetRunTime64();
srand(0); for (uint32 i=0; i<NUM_ITEMS; i++) table.Put(String("%1").Arg (rand()), String("%1").Arg(rand())); // we want this to be repeatable, hence sr and(0) srand(0); for (uint32 i=0; i<NUM_ITEMS; i++) sTable.Put(String("%1").Ar g(rand()), String("%1").Arg(rand())); // we want this to be repeatable, hence s rand(0)
AddTally(tallies, "place", startTime, NUM_ITEMS); AddTally(tallies, "place", startTime, NUM_ITEMS);
startTime = GetRunTime64(); startTime = GetRunTime64();
table.SortByValue(); sTable.SortByValue();
AddTally(tallies, "sort", startTime, NUM_ITEMS); AddTally(tallies, "sort", startTime, NUM_ITEMS);
startTime = GetRunTime64(); startTime = GetRunTime64();
testCopy = table; // just to make sure copying a table works testCopy = sTable; // just to make sure copying a table works
AddTally(tallies, "copy", startTime, NUM_ITEMS); AddTally(tallies, "copy", startTime, NUM_ITEMS);
startTime = GetRunTime64(); startTime = GetRunTime64();
if (testCopy != table) bomb("Copy was not the same!"); if (testCopy != sTable) bomb("Copy was not the same!");
AddTally(tallies, "compare", startTime, NUM_ITEMS); AddTally(tallies, "compare", startTime, NUM_ITEMS);
startTime = GetRunTime64(); startTime = GetRunTime64();
if (testCopy.IsEqualTo(table, true) == false) bomb("Copy was not the sa me, considering ordering!"); if (testCopy.IsEqualTo(sTable, true) == false) bomb("Copy was not the s ame, considering ordering!");
AddTally(tallies, "o-compare", startTime, NUM_ITEMS); AddTally(tallies, "o-compare", startTime, NUM_ITEMS);
startTime = GetRunTime64(); startTime = GetRunTime64();
table.Clear(); sTable.Clear();
AddTally(tallies, "clear", startTime, NUM_ITEMS); AddTally(tallies, "clear", startTime, NUM_ITEMS);
} }
printf("STRING GRAND AVERAGES OVER ALL " UINT32_FORMAT_SPEC " RUNS ARE:\n" , NUM_RUNS); printf("STRING GRAND AVERAGES OVER ALL " UINT32_FORMAT_SPEC " RUNS ARE:\n" , NUM_RUNS);
for (HashtableIterator<String, double> iter(tallies); iter.HasData(); iter ++) printf(" STRING %f items/second for %s\n", iter.GetValue()/NUM_RUNS, iter. GetKey()()); for (HashtableIterator<String, double> iter(tallies); iter.HasData(); iter ++) printf(" STRING %f items/second for %s\n", iter.GetValue()/NUM_RUNS, iter. GetKey()());
} }
PrintAndClearStringCopyCounts("After String Sort test"); PrintAndClearStringCopyCounts("After String Sort test");
printf("Begin torture test!\n"); printf("Begin torture test!\n");
_state = 4; _state = 4;
{ {
 End of changes. 17 change blocks. 
20 lines changed or deleted 20 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)