Uploaded image for project: 'C++ Standard Library'
  1. C++ Standard Library
  2. STDCXX-493

std::string::append() slow

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 4.1.3
    • Fix Version/s: 4.2.0
    • Component/s: 21. Strings
    • Labels:
      None
    • Environment:

      gcc 4.1.2 on Linux/x86_64

      Description

      This is a similar problem to STDCXX-492: all overloads of string::append() are slower than the same overloads in gcc:

      $ let n=0; while [ $n -lt 3 ]; do time LD_LIBRARY_PATH=../lib ./append-stdcxx-4.1.3 500000000 $n; let n=`expr $n + 1`; done

      real 0m11.221s
      user 0m9.941s
      sys 0m1.104s

      real 0m13.065s
      user 0m11.661s
      sys 0m1.236s

      real 0m7.837s
      user 0m6.660s
      sys 0m1.160s

      $ let n=0; while [ $n -lt 3 ]; do time ./append-gcc-4.1.2 500000000 $n; let n=`expr $n + 1`; done

      real 0m4.865s
      user 0m4.172s
      sys 0m0.692s

      real 0m7.617s
      user 0m6.920s
      sys 0m0.696s

      real 0m5.787s
      user 0m5.068s
      sys 0m0.720s

      The program I used to do the comaprison is below:

      #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.append (1, 'x'); }

      else if (op == 1)

      { for (int i = 0; i < N; ++i) str.append ("x"); }

      else

      { for (int i = 0; i < N; ++i) str.append (x); }

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

        Attachments

        1. stdcxx-493.patch
          2 kB
          Travis Vitek

          Activity

            People

            • Assignee:
              vitek Travis Vitek
              Reporter:
              mbrown Mark Brown

              Dates

              • Created:
                Updated:
                Resolved:

                Issue deployment