#include #include "RNGT.h" #include #include "StopWatchT.h" #include #include // for strcmp using namespace std; int main(int argc, char * argv[]) { int trials{10}; int length{100}; int keyLength{10}; string word,key; int i; int trial; StopWatchT timer; size_t pos; int arg = 1; while (arg < argc) { if (!strcmp(argv[arg] ,"-t")) { ++arg; if ( arg < argc){ trials = atoi(argv[arg++]); if (trials < 0) { trials = 10; } } } else if (!strcmp(argv[arg] ,"-l")) { ++arg; if( arg < argc){ length = atoi(argv[arg++]); if (length < 0) { length = 100; } } } else if (!strcmp(argv[arg] ,"-k")) { if(++arg < argc){ keyLength = atoi(argv[arg++]); keyLength = max(keyLength, 1); } } else { cout << "Unused arg " << argv[arg] << endl; ++arg; } } RNGT source(static_cast('a'), static_cast('z')); for(trial = 0; trial < trials; ++trial){ word = ""; for( i = 0; i < length; ++i) { word += static_cast(source()); } key = ""; for(i = 0; i < keyLength; ++i) { key += static_cast(source()); } timer.Continue(); int finds{0}; for(pos = word.find(key); pos != string::npos; pos = word.find(key,pos+1)){ finds++; } timer.Stop(); } cout << timer.TimeInUnit(TimeUnitT::MILLISECOND) << endl; return 0; }