// SubArraySumTimer.cpp // Implement and time several algorithms for the Best // Subarray Sum problem. // The problem instances are created randomly. // 15 oct 04 tom bailey // Revisions by tom bailey 16 oct 08 // Replaced timer with hrTimer #include using std::vector; #include "RanGen.h" #include "SASSolver.h" #include using std::cout; using std::cin; using std::endl; #include "hrTimer.h" #include vector makeArray( RanGen * rg, double lower, double upper, long n ); void main( ) { double const lower = -20; double const upper = +10; double const minTime = 2.0; RanGen * rg = new RanGen( long( time( NULL ) ) ); cout << "How many tests, test vector size: "; int many; int size; cin >> many >> size; for( int i=0; i test = makeArray( rg, lower, upper, size ); for( size_t k=0; k> n; while( n > 0 ) { cout << endl << "Algorithm " << alg << ", " << n << " items "; Timer watch; long runs = 0; while( watch() < minTime ) { vector instance = makeArray( rg, lower, upper, n ); cout << "."; watch.start(); sas = alg.bestSum( instance ); watch.stop(); runs++; } cout << endl << "Algorithm " << alg << ", " << n << " items, " << runs << " runs, " << watch()/runs << " seconds per run" << endl << endl; cout << "Enter size: "; cin >> n; } } } vector makeArray( RanGen * rg, double lower, double upper, long n ) { vector v; for( int i=0; iunif() ); } return v; }