Hi Walter,
I have implemented your suggestion in rootcint. Now in CVS.
I have run a benchmark using $ROOTSYS/test/bench on several machines.
There is a slight improvement with some compilers.
Times are in CPU seconds.
I would be interested to know if you see an improvement in your case.
OS/compiler old new
linux/gcc2.95 3.51 3.47
linux/egcs1.1 3.75 3.65
alpha/cxx6 5.29 4.91
alpha/gcc 5.91 5.82
Solaris/CC5.2 6.19 6.32
sgi/gcc 6.37 6.01
sgi/cc 6.41 6.73
sgi/kcc 6.77 7.63
hpux/aCC 10.67 10.59
Win32/VisualC++ 10.33 10.79
Rene Brun
Walter F.J. Mueller wrote:
>
> Hi ROOTers,
>
> Currently (ROOT 3.02/03) the read part of an automatically generated
> streamer contains for reading of a STL vector code like
>
> fCoeff.clear();
> int R__i, R__n;
> R__b >> R__n;
> for (R__i = 0; R__i < R__n; R__i++) {
> double R__t;
> R__b >> R__t;
> fCoeff.push_back(R__t);
> }
>
> This works, but can cause an unnecessary amount of reallocations of the
> vector. Since the number of elements to be inserted is known up front
> this can be avoided by requesting enough capacity before the elements
> are inserted by calling the reserve() method ahead of time, like in
>
> fCoeff.clear();
> int R__i, R__n;
> R__b >> R__n;
> fCoeff.reserve(R__n);
> for (R__i = 0; R__i < R__n; R__i++) {
> ... as before ...
>
> This ensures that at most one reallocation is done when a vector is read.
> Only vectors and strings provide capacity management, so in practice this
> is only relevant for STL vectors and can't be applied to deque's ect.
>
> It be nice if rootcint would generate code like this. I haven't checked
> what the StreamerInfo based I/O does, but also there this might help.
>
> Cheers, Walter
>
> --
> Walter F.J. Mueller Mail: W.F.J.Mueller@gsi.de
> GSI, Abteilung KP3 Phone: +49-6159-71-2766
> D-64291 Darmstadt FAX: +49-6159-71-2989
> WWW: http://www-kp3.gsi.de/www/kp3/people/mueller.html
> PGP: http://www-kp3.gsi.de/~mueller/pgp.shtml
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:10 MET