1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | class timer { public: timer() { _start_time = std::clock(); } void restart() { _start_time = std::clock(); } double elapsed() const { return double(std::clock() - _start_time) / CLOCKS_PER_SEC; } double elapsed_max() const { return (double(std::numeric_limits<std::clock_t>::max()) - double(_start_time)) / double(CLOCKS_PER_SEC); } double elapsed_min() const { return double(1)/double(CLOCKS_PER_SEC); } private: std::clock_t _start_time; }; // timer |
1 2 3 | int ( CMyClass::*ptMemberFunc )() = &CMyClass::MemberFunc; CMyClass instance; (instance.*ptMemberFunc)(); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #include <vector> using namespace std; …… typedef int ( *ptFuncDef )(); vector< ptFuncDef > ptFuncVec; timer ttimer; ptFuncVec.push_back( &CMyClass::foobar1 ); ptFuncVec.push_back( &CMyClass::foobar2 ); for (int i = 0; i < ptFuncVec.size(); i++) { ttimer.restart(); ptFuncVec() fprintf( fh, "%8.2g\n", ttimer.elasped() ); ...... } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |