You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by Ravi Inampudi <in...@roguewave.com> on 2006/08/12 00:00:41 UTC

ostringstream performance

Hello,

I have a customer using the ostringstream who is running the following test case which is taking more than twice the amount between SourcePro ed 4 and ed 7. I also tried with ed 9 and found the performance a little better than ed 7 but still slower. Using quantify, the possible source of the slowdown seem to happen in include/streambuf.cc, xsputn()'s for loop .  Any known issues?  Timing results are shown below.

Ravi


// test_portal.cpp

#include <string>
#include <sstream>

// 8 char str
static const char test_str[] = "8 chars ";
std::string teststr(test_str);

void appendStreamTest()
{
  std::ostringstream strm;
  for (int i = 0; i < 256; i++)
  {
    strm << teststr;
  }
  std::string str = strm.str();
}

int main()
{
  for (int i = 0; i < 10000; i++)
  {
    appendStreamTest();
  }
  return 0;
}


1. SourcePro ed9:sol10:studio10 

time test_portal

real    0m7.01s
user    0m6.83s
sys     0m0.02s

2. SourcePro ed7:sol9:studio8

time test_portal

real    0m8.95s
user    0m8.81s
sys     0m0.04s

3. SourcePro ed4:sol8:studio7 

time test_portal

real    0m3.13s
user    0m3.11s
sys     0m0.02s

Re: ostringstream performance

Posted by Martin Sebor <se...@roguewave.com>.
Ravi Inampudi wrote:
> Hello,
> 
> I have a customer using the ostringstream who is running the following test case which is taking more than twice the amount between SourcePro ed 4 and ed 7. I also tried with ed 9 and found the performance a little better than ed 7 but still slower. Using quantify, the possible source of the slowdown seem to happen in include/streambuf.cc, xsputn()'s for loop .  Any known issues?  Timing results are shown below.

It could be this issue:
http://issues.apache.org/jira/browse/STDCXX-149

Note that the inefficient behavior was mandated by the C++ standard
(and effectively still is, until the new standard is issued). The
development version of stdcxx implements the accepted resolution
and runs quite a bit faster (all there compiled at -O):

   # stdcxx 4.2 (unreleased)
   real    0m1.516s
   user    0m1.494s
   sys     0m0.018s

   # Sun C++ 5.8
   real    0m3.256s
   user    0m3.024s
   sys     0m0.033s

   # Sun C++ 5.8 with -library=stdlport4
   real    0m2.065s
   user    0m1.915s
   sys     0m0.024s

Martin