Issue Details (XML | Word | Printable)

Key: STDCXX-492
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Travis Vitek
Reporter: Mark Brown
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
C++ Standard Library

std::string::operator+=() slow

Created: 22/Jul/07 08:58 PM   Updated: 24/Sep/07 10:45 PM
Return to search
Component/s: 21. Strings
Affects Version/s: 4.1.3
Fix Version/s: 4.2.0

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works 21.string.append.perf.cpp 2007-09-24 09:17 PM Travis Vitek 2 kB
Text File Licensed for inclusion in ASF works string.patch 2007-09-24 09:16 PM Travis Vitek 6 kB
Environment: gcc 4.1.2 on Linux/x86_64
Issue Links:
Reference
 

Patch Info: Patch Available
Severity: Inefficiency
Resolution Date: 24/Sep/07 10:45 PM


 Description  « Hide
Comparing overloads of string::operator+=() in stdcxx with the same functions in gcc 4.1.2, stdcxx is up to twice slower than gcc:

$ time ./op_plus_equal-stdcxx 100000000 0

real 0m2.241s
user 0m1.932s
sys 0m0.204s
$ time ./op_plus_equal-stdcxx 100000000 1

real 0m2.540s
user 0m2.344s
sys 0m0.196s
$ time ./op_plus_equal-stdcxx 100000000 2

real 0m1.492s
user 0m1.308s
sys 0m0.184s
$ time ./op_plus_equal-gcc 100000000 0

real 0m0.883s
user 0m0.728s
sys 0m0.156s
$ time ./op_plus_equal-gcc 100000000 1

real 0m1.589s
user 0m1.424s
sys 0m0.168s
$ time ./op_plus_equal-gcc 100000000 2

real 0m1.131s
user 0m0.976s
sys 0m0.156s

#include <cassert>
#include <cstdlib>
#include <string>

int main (int argc, char *argv[])
{
const int N = argc < 2 ? 1 : std::atoi (argv [1]);
const int op = argc < 3 ? 0 : std::atoi (argv [2]);

std::string str;

const std::string x ("x");

if (op == 0) { for (int i = 0; i < N; ++i) str += 'x'; } else if (op == 1) { for (int i = 0; i < N; ++i) str += "x"; } else { for (int i = 0; i < N; ++i) str += x; }

assert (str.size () == std::size_t (N));
}



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
No work has yet been logged on this issue.