///////////////////////////////////////////////////////////////////////////// // algor.cpp - demonstrate performance implications of STL algorithms // // Jim Fawcett, CSE691 - SW Modeling & Analysis, Fall 2000 ///////////////////////////////////////////////////////////////////////////// // Platform: Dell XPS1000, Windows 2000 Professional, SP1 #pragma warning(disable : 4786) #include #include #include #include #include "..\timer.h" using namespace std; ///////////////////////////////////////////////////////////////////////////// // populate container template void fill(cont &c, int N) { for(int i = 0; i elem globalSearch(cont &c, elem e) { static bool first = true; if(first) { cout << "\n using global find function"; first = false; } return *find(c.begin(), c.end(), e); } ///////////////////////////////////////////////////////////////////////////// // search with member find template elem memberSearch(cont &c, elem e) { static bool first = true; if(first) { cout << "\n using member find function"; first = false; } return *c.find(c.begin(), c.end(), e); } // ///////////////////////////////////////////////////////////////////////////// // search with member find - specialization for set template elem memberSearch(set &c, elem e) { static bool first = true; if(first) { cout << "\n using member find function"; first = false; } return *c.find(e); } ///////////////////////////////////////////////////////////////////////////// // function to time function calls template clock_t timeFunction(U(*pFunc)(V v, U u), V v, U u, int N) { timer t; t.start(); int i; for(i=0; i dSet; fill,double>(dSet,Nfill); double d = rand(); timeFunction&>(globalSearch,dSet,d,Nrun); timeFunction&>(memberSearch,dSet,d,Nrun); list dList; fill,double>(dList,Nfill); timeFunction&>(globalSearch,dList,d,Nrun); cout << "\n\n"; }