///////////////////////////////////////////////////////////////////////////// // exPerf.cpp - demonstrate performance of Standard C++ exceptions // // Jim Fawcett, ELE591/791 - Intelligent Systems, Summer 2000 ///////////////////////////////////////////////////////////////////////////// #include #include #include #include "..\timer.h" ///////////////////////////////////////////////////////////////////////////// // test with exceptions void testWexcept(bool condition) { static bool first = true; if(first) { std::cout << "\n using exceptions"; first = false; } try { // Sleep(10); // simulate some processing; if(condition) throw exception(); } catch(exception &e) { std::cout << e.what() << std::endl; } }; ///////////////////////////////////////////////////////////////////////////// // test without exceptions void testWOexcept(bool) { static bool first = true; if(first) { std::cout << "\n not using exceptions"; first = false; } //Sleep(10); } // ///////////////////////////////////////////////////////////////////////////// // function to time function calls template clock_t timeFunction(void(*pFunc)(arg a), arg a, int N) { timer t; t.start(); int i; for(i=0; i(testWexcept, false, N); timeFunction(testWOexcept, false, N); std::cout << "\n\n"; }