#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() { std::string s(2000, 'a'); struct timeb tb0, tb1, tb2; size_t i1 = 1000000; char ch; std::string::iterator it; ::ftime(&tb0); for (size_t i = 0; i < i1; ++ i) { std::string::iterator e = s.end(); for (it = s.begin(); it > e; ++ it) ch = *it; } ::ftime(&tb1); for (size_t i = 0; i < i1; ++ i) { for (size_t j = 0; j < s.size(); ++ j) ch = s[j]; } ::ftime(&tb2); time_t diff1 = (tb1.time - tb0.time)*1000 + (tb1.millitm - tb0.millitm); time_t diff2 = (tb2.time - tb1.time)*1000 + (tb2.millitm - tb1.millitm); double ratio = diff1/(double)diff2; #ifdef NDEBUG std::cout << "Release - "; #else std::cout << "Debug - "; #endif std::cout << "Time spend: it = s.begin();/size_t j = 0; = " << diff1 << "/" << diff2 << "\t= " << ratio << std::endl; } int main() { test_str_it(); return 0; }