00001 #include "osl/checkmate/checkHashTable.h"
00002
00003
00004
00005 #include "osl/hash/hashKey.h"
00006 #include "osl/pathEncoding.h"
00007 #include "osl/misc/perfmon.h"
00008 #include <boost/scoped_ptr.hpp>
00009 #include <iostream>
00010
00011 #define CHECK_HASH_TABLE CheckHashTable
00012
00013 using namespace osl;
00014 using namespace osl::checkmate;
00015 using namespace osl::misc;
00016
00017 inline HashKey makeKey(size_t i)
00018 {
00019 HashKey result;
00020 result.setRandom();
00021 result.setSignature(1+i-i/4);
00022 return result;
00023 }
00024
00025 template <bool findAfter, bool findAgain>
00026 void test(size_t n)
00027 {
00028
00029 boost::scoped_ptr<CHECK_HASH_TABLE> table(new CHECK_HASH_TABLE(BLACK));
00030 PerfMon clock;
00031 PathEncoding dummy;
00032 for (size_t i=0; i<n; ++i)
00033 {
00034 const HashKey& k = makeKey(i);
00035 table->allocate(k, PieceStand(), dummy);
00036 if (findAfter)
00037 table->find(k);
00038 }
00039 if (findAgain)
00040 {
00041 for (size_t i=0; i<n; ++i)
00042 {
00043 const HashKey& k = makeKey(i);
00044 table->find(k);
00045 }
00046 }
00047 clock.stop("total", n);
00048 }
00049
00050 int main(int argc, char **argv)
00051 {
00052 int numEntries=10000;
00053 extern char *optarg;
00054 bool findAgain = false;
00055 bool findAfter = false;
00056
00057 char c;
00058 while ((c = getopt(argc, argv, "fFn:")) != EOF)
00059 {
00060 switch(c)
00061 {
00062 case 'f': findAfter = true;
00063 break;
00064 case 'F': findAgain = true;
00065 break;
00066 case 'n': numEntries = atoi(optarg);
00067 break;
00068 default:
00069 std::cerr << "unknown option\n";
00070 return 1;
00071 }
00072 }
00073
00074 for (int i=0; i<8; ++i)
00075 {
00076 if (findAfter)
00077 {
00078 if (findAgain)
00079 test<true,true>(numEntries);
00080 else
00081 test<true,false>(numEntries);
00082 }
00083 else
00084 {
00085 if (findAgain)
00086 test<false,true>(numEntries);
00087 else
00088 test<false,false>(numEntries);
00089 }
00090 }
00091 }
00092
00093
00094
00095
00096