Welcome to the { mindfrost82.com } forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Programming > C++

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-10-2008, 06:49 AM
Peng Yu
 
Posts: n/a
How to stl library efficiently?

Hi,

I came across some discussion on that improper usage stl library could
make program performance bad. Some tips are trivial, such as using the
appropriate algorithm, choosing the best data structure (say, vector
vs. list).

I'm wondering whether are less obvious tricks to make stl based
program performance as good as the hard coded C program?

Thanks,
Peng

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Reply With Quote
  #2 (permalink)  
Old 08-10-2008, 05:03 PM
Ulrich Eckhardt
 
Posts: n/a
Re: How to stl library efficiently?

Peng Yu wrote:
> I came across some discussion on that improper usage stl library could
> make program performance bad. Some tips are trivial, such as using the
> appropriate algorithm, choosing the best data structure (say, vector
> vs. list).


There is also deque as possible unordered container. BTW, can you supply a
URL of mentioned discussion?

> I'm wondering whether are less obvious tricks to make stl based
> program performance as good as the hard coded C program?


It's a very obvious trick but it still applies here: profile first, optimise
later.

Lastly: the STL was in large parts incorporated into the C++ stardardlibrary
but the overlap is not 100%. I'd generally target my code at the C++
standardlibrary, the STL itself is pretty much dead nowadays.


Uli


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Reply With Quote
  #3 (permalink)  
Old 08-10-2008, 05:28 PM
red floyd
 
Posts: n/a
Re: How to stl library efficiently?

Peng Yu wrote:
> Hi,
>
> I came across some discussion on that improper usage stl library could
> make program performance bad. Some tips are trivial, such as using the
> appropriate algorithm, choosing the best data structure (say, vector
> vs. list).
>
> I'm wondering whether are less obvious tricks to make stl based
> program performance as good as the hard coded C program?
>


Get Scott Meyer's "Effective STL".

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Reply With Quote
  #4 (permalink)  
Old 08-10-2008, 05:28 PM
Mathias Gaunard
 
Posts: n/a
Re: How to stl library efficiently?

On 10 août, 07:49, Peng Yu <PengYu...@gmail.com> wrote:
> I'm wondering whether are less obvious tricks to make stl based
> program performance as good as the hard coded C program?


You need move semantics and in-place construction for comparable
performance.
Which are not in the current implementation.


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Reply With Quote
  #5 (permalink)  
Old 08-12-2008, 09:41 PM
Lance Diduck
 
Posts: n/a
Re: How to stl library efficiently?

> I'm wondering whether are less obvious tricks to make stl based
> program performance as good as the hard coded C program?
>
> Thanks,
> Peng

Typically, STL based programs are already faster than hand coded C
programs. See sites like http://theory.stanford.edu/~amitp/rants/c++-vs-c/
and http://www.tilander.org/aurora/2007/...and-qsort.html

Outside of the advice to always select the proper container and
algorithms, there are other tricks one can do to improve performance.
Most of these involve using custom allocators in containers. Here are
some papers http://xushiwei.com/allocators-perfo...tl-collections,
and http://www.open-std.org/jtc1/sc22/wg...2007/n2486.pdf

There are a number of platform specific ways to improve performance.
On MSVC, define _SECURE_SCL=0 to get rid of a lot of overhead for
security checks. On gcc, this is a good read
http://www.open-std.org/jtc1/sc22/wg...007/n2271.html.

If these still arent good enough, the next thing is to define your own
containers and algorithms. The STL defines a number of concepts to use
for this. For example, you may design your own version of of a sorted
container tailored to your needs, and if you follow the guidelines
your container will play nice with all of the other STL components.
See http://www.cs.rpi.edu/~musser/STL_concept_web/ and
http://www.sgi.com/tech/stl/Container.html. boost has a lot of STL
based containers, as well as gcc for example
http://gcc.gnu.org/onlinedocs/libstd...ontainers.html

Lance




--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Reply With Quote
  #6 (permalink)  
Old 08-13-2008, 07:24 PM
Sergey P. Derevyago
 
Posts: n/a
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....2ce202a371778b

-----------------------------------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! ]

Reply With Quote
  #7 (permalink)  
Old 08-17-2008, 07:51 PM
Peng Yu
 
Posts: n/a
Re: How to stl library efficiently?

> The table athttp://ders.stml.net/cpp/mtprog/mtprog.html#3.1.1shows
> that start_ders() function is tens and hundreds (!!!) of times faster:


The website you mentioned in some language rather than English (maybe
Russian). I don't understand that language. Is there an English
version for it.

Thanks,
Peng


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Reply With Quote
  #8 (permalink)  
Old 08-17-2008, 07:52 PM
Peng Yu
 
Posts: n/a
Re: How to stl library efficiently?

On Aug 10, 11:03 am, Ulrich Eckhardt <dooms...@knuut.de> wrote:
> Peng Yu wrote:
> > I came across some discussion on that improper usage stl library could
> > make program performance bad. Some tips are trivial, such as using the
> > appropriate algorithm, choosing the best data structure (say, vector
> > vs. list).

>
> There is also deque as possible unordered container. BTW, can you supply a
> URL of mentioned discussion?


I came across such webpage long time back. I can recall where it is.
Sorry about that.

> > I'm wondering whether are less obvious tricks to make stl based
> > program performance as good as the hard coded C program?

>
> It's a very obvious trick but it still applies here: profile first, optimise
> later.
>
> Lastly: the STL was in large parts incorporated into the C++ stardardlibrary
> but the overlap is not 100%. I'd generally target my code at the C++
> standardlibrary, the STL itself is pretty much dead nowadays.


I always use the following website for the documentation when I use
STL.
http://www.sgi.com/tech/stl/

Where is the C++ Standard Library manual? I found this one
http://gcc.gnu.org/onlinedocs/libstdc++/. Is it appropriate?

What is the major difference between C++ Standard Library and STL? I
usually use GCC C++ compiler. It has the complete C++ Standard
Library, right?

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Reply With Quote
  #9 (permalink)  
Old 08-17-2008, 07:52 PM
Peng Yu
 
Posts: n/a
Re: How to stl library efficiently?

On Aug 10, 11:28 am, red floyd <no.spam.h...@example.com> wrote:
> Peng Yu wrote:
> > Hi,

>
> > I came across some discussion on that improper usage stl library could
> > make program performance bad. Some tips are trivial, such as using the
> > appropriate algorithm, choosing the best data structure (say, vector
> > vs. list).

>
> > I'm wondering whether are less obvious tricks to make stl based
> > program performance as good as the hard coded C program?

>
> Get Scott Meyer's "Effective STL".


It seems that it is a little bit outdated. For example, it mentioned
auto_ptr, but people usually use boost::shared_ptr. I'm wondering what
are the things that have been changed since the book was written.

Thanks,
Peng

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Reply With Quote
  #10 (permalink)  
Old 08-18-2008, 02:58 PM
=?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=
 
Posts: n/a
Re: How to stl library efficiently?

On 2008-08-17 20:52, Peng Yu wrote:
> On Aug 10, 11:03 am, Ulrich Eckhardt <dooms...@knuut.de> wrote:
>> Peng Yu wrote:
>> > I came across some discussion on that improper usage stl library could
>> > make program performance bad. Some tips are trivial, such as using the
>> > appropriate algorithm, choosing the best data structure (say, vector
>> > vs. list).

>>
>> There is also deque as possible unordered container. BTW, can you supply a
>> URL of mentioned discussion?

>
> I came across such webpage long time back. I can recall where it is.
> Sorry about that.
>
>> > I'm wondering whether are less obvious tricks to make stl based
>> > program performance as good as the hard coded C program?

>>
>> It's a very obvious trick but it still applies here: profile first, optimise
>> later.
>>
>> Lastly: the STL was in large parts incorporated into the C++ stardardlibrary
>> but the overlap is not 100%. I'd generally target my code at the C++
>> standardlibrary, the STL itself is pretty much dead nowadays.

>
> I always use the following website for the documentation when I use
> STL.
> http://www.sgi.com/tech/stl/
>
> Where is the C++ Standard Library manual? I found this one
> http://gcc.gnu.org/onlinedocs/libstdc++/. Is it appropriate?
>
> What is the major difference between C++ Standard Library and STL? I
> usually use GCC C++ compiler. It has the complete C++ Standard
> Library, right?


STL is the name that was used before it became part of the C++ standard,
the C++ standard library contains the STL and some other stuff (like IO
capabilities etc.), so you can say that the STL is a subset of the
standard library.

The gcc standard library implementation is probably close to complete,
you can probably find detailed information about its conformance at the
gnu site.

--
Erik Wikström


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Programming > C++


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 03:51 PM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0


Sponsors:
Bad Credit Mortgages | Remortgages | Montana Music | Mortgage | The eBay Song



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114