Thans for everyone. Maybe I was a little lazy. Now I gave the code test.
test 1: 158.751ms, so long, my god!
int main()
{
chrono::high_resolution_clock::time_point begin_time = chrono::high_resolution_clock::now();
for(int i=0;i<100000;i++)
{
//string str_1("hello ");
//string str_2("world");
stringstream ss;
ss << "hello " << "world";
const string dst_str = ss.str();
}
chrono:: high_resolution_clock::time_point stop_time = chrono::high_resolution_clock::now();
chrono::duration<double> slapsed = duration_cast<duration<double>>(stop_time - begin_time);
cout << "time takes " << slapsed.count() * 1000 << "ms" << endl;
return 0;
}
test 2: 31.1946ms, fastest!
int main()
{
chrono::high_resolution_clock::time_point begin_time = chrono::high_resolution_clock::now();
for(int i=0;i<100000;i++)
{
string str_1("hello ");
string str_2("world");
const string dst_str = str_1 + str_2;
}
chrono:: high_resolution_clock::time_point stop_time = chrono::high_resolution_clock::now();
chrono::duration<double> slapsed = duration_cast<duration<double>>(stop_time - begin_time);
cout << "time takes " << slapsed.count() * 1000 << "ms" << endl;
return 0;
}
test 3: use boost::filesystem::path 35.1769ms, also a nice choice
int main()
{
chrono::high_resolution_clock::time_point begin_time = chrono::high_resolution_clock::now();
for(int i=0;i<100000;i++)
{
string str_1("hello ");
string str_2("world");
boost::filesystem::path dst_path(str_1);
dst_path += str_2;
const string dst = dst_path.string();
}
chrono::high_resolution_clock::time_point stop_time = chrono::high_resolution_clock::now();
chrono::duration<double> slapsed = duration_cast<duration<double>>(stop_time - begin_time);
cout << "time takes " << slapsed.count() * 1000 << "ms" << endl;
return 0;
}
stringstreamplus the two insertions plus the call to.str().