#include #include #include /*! Test on appeand and operator +. case 1: + case 2: append() */ void test_str_append() { std::string firstlevel ("edu"); std::string secondlevel ("chem.brandeis"); std::string dir ("yanglingfa"); std::string scheme ("http://"); std::string url; std::string u; struct timeb tb0, tb1, tb2; size_t i1(100000); ::ftime(&tb0); for (size_t i = 0; i < i1; ++ i) { url = scheme + "hopf." + secondlevel + '.' + firstlevel + '/' + dir; } ::ftime(&tb1); for (size_t i = 0; i < i1; ++ i) { u = scheme; u.append("hopf."); u.append(secondlevel); u.append(1, '.'); u.append(firstlevel); u.append(1, '/'); u.append(dir); } ::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: operator +()/append() =" << diff1 << "/" << diff2 << "\t= " << ratio << std::endl; } int main() { test_str_append(); return 0; }