[Bug libstdc++/29037] performance problem with std::string operator=(const std::string& str);
neundorf at kde dot org
gcc-bugzilla@gcc.gnu.org
Tue Sep 12 17:04:00 GMT 2006
------- Comment #2 from neundorf at kde dot org 2006-09-12 17:04 -------
The use case here is as follows:
std::string cacheKey;
cacheKey.resize(4*1024);
for (...several files...)
{
cacheKey=current.FileName; // <- this is the critical line
for(std::vector<std::string>::const_iterator i =
this->IncludePath->begin(); i != this->IncludePath->end(); ++i)
{
cacheKey+=*i;
}
... do something
}
So in the line
cacheKey=current.FileName;
the allocated memory from the last loop iteration is thrown away, and then
allocated again bit by bit while appending the strings contained in the vector.
Changing the line to
cacheKey=current.FileName.c_str();
brought the execution time in one example from 19 seconds down to 15 seconds.
Alex
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29037
More information about the Gcc-bugs
mailing list