Performance Gcc 3.3.1 VS 2.95.1
Joe Buck
Joe.Buck@synopsys.COM
Wed Oct 27 17:53:00 GMT 2004
On Wed, Oct 27, 2004 at 01:37:16PM +0100, Mike Capp wrote:
> > Ouch! By manipulating the capacity in that way, you force quadratic
> > performance! The string has to be reallocated every time. Take out
> > your explicit management of capacity and things will get much faster.
>
> > If 2.95.1 ran this code faster, I assume it must have ignored your
> >calls to reserve().
>
> Not necessarily. basic_string::reserve guarantees *at least* the
> requested capacity; it may well allocate more. If, f'rinstance,
> 2.95.1 rounded reservations up to the next multiple of 64 chars, and
> 3.3.1 rounded up to the next multiple of 16, then 3.3.1 would need to
> reallocate more frequently, explaining the OP's performance
> observations.
Yes, you're right, and my remark about "ignored your calls to reserve()"
is not; your point that differences in the implementation may affect
the result is correct.
I would recommend using reserve() only to reserve a whole lot of space
and thereby do only one reallocation instead of many.
More information about the Gcc
mailing list