[RFA] Algorithms vs operator* and operator==

Paolo Carlini pcarlini@suse.de
Thu Nov 4 13:20:00 GMT 2004


Hi,

seems to me the natural development of the improvements to locale_facets
and stl_numeric but want to make sure I'm not missing something before
actually starting on it.

The fundamental observation is rather trivial: for a generic input_iterator
both operator* and operator== can be expensive and we should do our best
to minimize the number of calls throughout in the library.

This morning I changed tentatively std::replace_copy (see attached) and
benchmarked this type of test on my home machine:

  typedef istreambuf_iterator<char> iterator_type;
 
  istringstream iss("precipitevolissimevolmente");
  iterator_type beg(iss);
  iterator_type end;

  char buffer[26];

  for (unsigned i = 0; i < 10000000; ++i)
    {
      replace_copy(beg, end, buffer, 'i', 'z');
      iss.seekg(0);
    }

These are the numbers:

patched
=======
5.020u 0.010s 0:05.06 99.4%     0+0k 0+0io 203pf+0w

current
=======
6.130u 0.000s 0:06.16 99.5%     0+0k 0+0io 205pf+0w

Of course, I have also verified that there are no bad consequences when
beg and end are actually just random_access_iterators (the compiler
should be able to easily const propagate __value)

Can you spot anything wrong with this kind of change? If we agree that
it's good, there are quite a few places to tweak, both in stl_algo and
in stl_algobase (besides locale_facets ;)

Paolo.

/////////////
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patch_replace_copy
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20041104/93fdef2f/attachment.ksh>


More information about the Libstdc++ mailing list