百万级以上字符串拼接建议使用append
string str;
clock_t c = clock();
//执行100w次
for (int i = 0; i < 1000000; i++)
{
str = str + "hello";//最慢,基本卡死
}
clock_t c2 = clock();
//+= 0.183ms append 0.17ms
cout << double(c2 - c) / CLOCKS_PER_SEC << endl;
百万级以上字符串拼接建议使用append
string str;
clock_t c = clock();
//执行100w次
for (int i = 0; i < 1000000; i++)
{
str = str + "hello";//最慢,基本卡死
}
clock_t c2 = clock();
//+= 0.183ms append 0.17ms
cout << double(c2 - c) / CLOCKS_PER_SEC << endl;