469,271 Members | 1,600 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

optimizing c++ code (on win32 platform), all the techniques you know?

Hi,

"What methods do you ever use to optimize the programs?"

We're developing a graphics chip emulator in C++, but it's very slow
for big scenes. Even though this is a cross-platform software, I only
want to optimize it on the Win32 (Windows 2000/XP) platform.

I've tried the following method to optimize it:

* Boost.Pool - a fast memory allocation algoritm, fixed-size chunks.
<http://www.boost.org/libs/pool/doc/index.html>

* Whole Program Optimization with Visual C++ .NET
<http://www.codeproject.com/tips/gloption.asp>
I almost turn on every possbile Visual C++ options to optimize the
speed.

* inline every possbile function
Not tried yet:

* Improving Runtime Performance with the Smooth Working Set Tool
<http://msdn.microsoft.com/msdnmag/issues/1000/bugslayer/default.aspx>
I don't think it will help much, because our program is about 500KB.
Or not?

* Recompile the CRT with _fastcall calling convetion

* Link single-thread CRT instead of multi-thread CRT
We don't use many CRT functions.

* Distributed Computing
<http://www-unix.mcs.anl.gov/mpi/>
Uh, not feasible. I am looking for "fast" approches, like a compiler
option, etc.

--
Tzu-Chien Chiu
XGI Technology, Inc - Extreme Graphics Innovaion
Jul 19 '05 #1
9 3750
Tzu-Chien Chiu <tz***********@xgitech.com> wrote in message
news:03*******@comp.compilers...
Hi,

"What methods do you ever use to optimize the programs?"
We're developing a graphics chip emulator in C++, but it's very slow
for big scenes. Even though this is a cross-platform software, I only
want to optimize it on the Win32 (Windows 2000/XP) platform.
This question isn't suitable for c.l.c++, at least where a specific
implementation is concerned.
I've tried the following method to optimize it:

* Boost.Pool - a fast memory allocation algoritm, fixed-size chunks.
<http://www.boost.org/libs/pool/doc/index.html>
Or ditch memory allocation altogether, at least in the most critical parts
of your code. Many firmware engineers manage to design their systems to
_never_ do a memory allocation except during initialization, since a
recurring memory leak, even a small one, means death for an embedded system.

* Whole Program Optimization with Visual C++ .NET
<http://www.codeproject.com/tips/gloption.asp>
I almost turn on every possbile Visual C++ options to optimize the
speed.
It goes without saying to generate the fastest code possible, but this is
off-topic here.

* inline every possbile function
Well, every one that could possibly have a significant effect, which would
be the ones that a) do or might return quickly, and b) are called very
often. There's no point in spending hours moving functions to header files
if a cursory analysis of the program shows that doing so will make an
insiginificant difference.

Not tried yet:

* Improving Runtime Performance with the Smooth Working Set Tool
<http://msdn.microsoft.com/msdnmag/issues/1000/bugslayer/default.aspx>
I don't think it will help much, because our program is about 500KB.
Or not?

* Recompile the CRT with _fastcall calling convetion

* Link single-thread CRT instead of multi-thread CRT
We don't use many CRT functions.

* Distributed Computing
<http://www-unix.mcs.anl.gov/mpi/>
Uh, not feasible. I am looking for "fast" approches, like a compiler
option, etc.


I don't see anything relevant to c.l.c++ in all this.

Have you thought of redesigning your algorithms so they work more
efficiently? That's more likely to make a bigger difference than squeezing
out 10% better performance by quick or mechanical means such as compiler
options or moving code about.

DW

Jul 19 '05 #2
"Tzu-Chien Chiu" <tz***********@xgitech.com> wrote in message
"What methods do you ever use to optimize the programs?"

We're developing a graphics chip emulator in C++, but it's very slow
for big scenes. Even though this is a cross-platform software, I only
want to optimize it on the Win32 (Windows 2000/XP) platform.


Actually, the most efficient method is detect your bottleneck first. Before
you know exactly where most of time is wasted, any speculations about
optimization are pointless. It can be that your program spend 1% of time in
allocations and 90% of time in buffer transfers, so even if the miracle will
happen and you'll succeed to accelerate allocations twice, then still you'll
gain only 0.5% in overall time. And you can spend hours and days by
optimizing not relevant parts of the program with negligible effect. I think
you got the idea. Here's the article for general reading:
"Optimization: Your Worst Enemy"
By Joseph M. Newcomer
<http://www.codeproject.com/tips/optimizationenemy.asp>

Jul 19 '05 #3
Tzu-Chien Chiu wrote:
"What methods do you ever use to optimize the programs?"

We're developing a graphics chip emulator in C++, but it's very slow
for big scenes. Even though this is a cross-platform software, I only
want to optimize it on the Win32 (Windows 2000/XP) platform.


If you application seems very slow on todays super fast GHz PC's, that
to me that suggests the application it is doing an awful lot of CPU
intensive stuff.

Have you profiled your application to check that the appliction is not
wasting time on a badly code algorithm or flow structure? Does you
machine have lots of spare RAM? RAM always helps speed up memory
hunger applications.

If you do have an optimal algorithm then your applicaiton is just CPU
intensive and I would be suprised if the any amount of optimazation
would greatly improve the speed.

Jussi Jumppanen
Author of: Zeus for Windows, Win32 (Brief, Emacs, etc) FTP Text Editor
"The C/C++, Java, HTML, FTP, Python, PHP, Perl programmer's editor"
Home Page: http://www.zeusedit.com
Jul 19 '05 #4
Jussi Jumppanen <ju****@zeusedit.com> writes:
Tzu-Chien Chiu wrote:
"What methods do you ever use to optimize the programs?"

We're developing a graphics chip emulator in C++, but it's very slow
for big scenes. Even though this is a cross-platform software, I only
want to optimize it on the Win32 (Windows 2000/XP) platform.


If you application seems very slow on todays super fast GHz PC's, that
to me that suggests the application it is doing an awful lot of CPU
intensive stuff.

[snip]

That is usually wrong. I/O speeds are hundres of thousands of times
slower than cpu speeds. The speed of a system is usually most
strongly dependent on the speed of its slowest parts. Many more
programs are I/O bound, and can be very slow even when only using
1 or 2% of cpu.

Memory-bound and system-call bound progams are also more common than
cpu-bound progams.
Jul 19 '05 #5
> * Boost.Pool - a fast memory allocation algoritm, fixed-size chunks.
<http://www.boost.org/libs/pool/doc/index.html>
when you use it wrong, you need much more memory than you actually need.
* Whole Program Optimization with Visual C++ .NET
<http://www.codeproject.com/tips/gloption.asp>
I almost turn on every possbile Visual C++ options to optimize the
speed.
Good idea, but some options can under certain circumstances create
errors in your executable
* inline every possbile function
That is very stupid. inlining very small functions that are called in
loops can be a good idea, but inlining every function in the program
is just stupid because it bloats the code which then makes code
caching very unefficient.
* Recompile the CRT with _fastcall calling convetion


This can lead to errors too. be very careful.

As the foreposter said, before you start wasting your time with
useless things like spending 90% time on things that comsumes 0.01% of
performance, detect what certain loops are slow, instead of
bit-fiddling rethink your algorithms.

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu
Jul 19 '05 #6
Have you try V-Tune, to find the bottleneck or the Intel-Compiler
sometimes it's helpfull

Oliver Wesnigk

"Tzu-Chien Chiu" <tz***********@xgitech.com> wrote in message
"What methods do you ever use to optimize the programs?"

Jul 19 '05 #7

Tzu-Chien Chiu wrote:
"What methods do you ever use to optimize the programs?"


Don't optimize your programs before you design them.

--
= Jeff Kenton Consulting and software development =
= http://home.comcast.net/~jeffrey.kenton =
Jul 19 '05 #8
WW
Tzu-Chien Chiu wrote:

"What methods do you ever use to optimize the programs?"


http://magnonel.guild.net/~schwern/t...imization.html

Short URL: http://tinyurl.com/ncpc

--
WW aka Attila

Jul 19 '05 #9
Tzu-Chien Chiu wrote:
"What methods do you ever use to optimize the programs?"


Read any book by Jon Bentley or containing the words "Programming
Pearls".

Thanks. Take care, Brian Inglis Calgary, Alberta, Canada
--
Br**********@CSi.com (Brian dot Inglis at SystematicSw dot ab dot ca)
fake address use address above to reply

Jul 19 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by A Future Computer Scientist | last post: by
3 posts views Thread by David Douard | last post: by
14 posts views Thread by Ian Richardson | last post: by
6 posts views Thread by Dylan | last post: by
7 posts views Thread by Kenjis Kaan | last post: by
1 post views Thread by hyena | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.