#include #include #include /*! Test on how does a string iteration should be ended. case 1: it > e; case 2: it != e; */ void test_str_it_end() { std::string s('a', 2); size_t n = s.size(); struct timeb tb0, tb1, tb2; int i1 = 1000000; int tmp; std::string::iterator it; ::ftime(&tb0); for (int i = 0; i < i1; ++ i) { std::string::iterator e = s.end(); for (it = s.begin(); it > e; ++ it) tmp = ::rand(); } ::ftime(&tb1); for (int i = 0; i < i1; ++ i) { std::string::iterator e = s.end(); for (it = s.begin(); it != e; ++ it) tmp = ::rand(); } ::ftime(&tb2); double diff1 = (tb1.time - tb0.time)*1000 + (tb1.millitm - tb0.millitm); double diff2 = (tb2.time - tb1.time)*1000 + (tb2.millitm - tb1.millitm); double ratio = diff1/diff2; #ifdef NDEBUG std::cout << "Release - "; #else std::cout << "Debug - "; #endif std::cout << "Time spend: it > e;/it != e; = " << diff1 << "/" << diff2 << "\t= " << ratio << std::endl; int tmp1 = tmp; } int main() { test_str_it_end(); return 0; }