This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Performance of the default node allocator.


On Thu, 2003-11-13 at 14:29, Alex Vinokur wrote:
> "Loren James Rittle" <rittle@latour.rsch.comm.mot.com> wrote in
message 200311110628.hAB6SL6c004734@latour.rsch.comm.mot.com">news:200311110628.hAB6SL6c004734@latour.rsch.comm.mot.com...
> 
> [snip]
> 
> Hi Loren,
> 
> I have several questions and some suggestions.
> 
> 
> > #include <iostream>
> > #include <algorithm>
> > #include <list>
>    #include <vector>
Ths won't work with vector, because std::list::sort does not copy the
elemnts, but moves them by adjusting the node pointers, so the elemnts
get kind of splayed in memory, and when the list is destroyed, then the
entries in the allocator free list are also splayed all around the
memory, however, if you use std::sort on list's iterators, (if it were
possible!!!) then you would get a much slower sort (not for int, and
double, but for heavy copy types), but the locality of node in memory
will be preserved. vector's memory is always contiguous, so nothing
happens there.


> > #include <memory>
> --------------------------------------------
> > #include <testsuite_performance.h>
> Does GNU gcc contain such testsuite_performance.h?
> --------------------------------------------
No, but if you download form cvs, you will get a directory named
testsuite which conatins these files.


> >
> > template <class T>
> > void clear_container (T& _cont) { T temp; std::swap (temp, _cont); }
> >
> vector<double> vect;
> > int main ()
> > {
> >   std::list <double> il;
> ------------------------------------
> >   using namespace __gnu_test;
> Can users (not only developers) use that namespace?
> I didn't find __gnu_test in g++ 3.3.1 (cygming special).
No, they can't __NAMES are reserved for library developers, and compiler
implementations.


> ------------------------------------
> >   time_counter time;
> >   resource_counter resource;
> >
> >   for (int x = 3; x--;)
> >     {
> >       srand(0);
>          vect.clear();
May not actually release memory!!! use clear_container instead!!!


>          for (int i = 0; i < SIZE; ++i) vect.push_back(rand()%300);
> >       start_counters(time, resource);
> --------- Remove? ---------
>          >       for (int i = 0; i < 700000; ++i)
> > il.push_back(rand()%300);
> --------------------------
>          for (int i = 0; i < 700000; ++i) push_back(vect[i])
> >       stop_counters(time, resource);
> >       report_performance(__FILE__, "insert", time, resource);
> >
> >       start_counters(time, resource);
> >       il.sort();
> >       stop_counters(time, resource);
> >       report_performance(__FILE__, "sort", time, resource);
> >
> >       start_counters(time, resource);
> >       clear_container(il);
> >       stop_counters(time, resource);
> >       report_performance(__FILE__, "clear", time, resource);
> >     }
> > }
> >
> 
> 
> --
>    =====================================
>    Alex Vinokur
>      mailto:alexvn@connect.to
>      http://mathforum.org/library/view/10978.html
>      news://news.gmane.org/gmane.comp.lang.c++.perfometer
>    =====================================
> 
> 
> 

-- 
	-Dhruv Matani.
http://www.geocities.com/dhruvbird/




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]