Re: How to stl library efficiently?
Peng Yu wrote:
I'm wondering whether are less obvious tricks to make stl based
program performance as good as the hard coded C program?
Sure.
Please read "C++ multithreading: mem_pool" message:
Message-ID: <4899c3e1$0$90276$14726298@news.sunsite.dk>
http://groups.google.com/group/comp.programming.threads/msg/b52ce202a371778b
-----------------------------------8<-----------------------------------
void start_std(void*)
{
list<int> lst;
for (int i=0; i<N; i++) {
for (int j=0; j<M; j++) lst.push_back(j);
for (int j=0; j<M; j++) lst.pop_front();
}
}
void start_ders(void*)
{
mem_pool mp;
stl_allocator<int> alloc(mp);
list<int, stl_allocator<int> > lst(alloc);
for (int i=0; i<N; i++) {
for (int j=0; j<M; j++) lst.push_back(j);
for (int j=0; j<M; j++) lst.pop_front();
}
}
-----------------------------------8<-----------------------------------
The table at http://ders.stml.net/cpp/mtprog/mtprog.html#3.1.1 shows
that start_ders() function is tens and hundreds (!!!) of times faster:
1 CPU : 38.1
1 CPU,HT : 42.1
2 CPU,SMP: 321.6 (!!!)
2 CPU,HT : 37.0
--
With all respect, Sergey. http://ders.stml.net/
mailto : ders at skeptik.net
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]