C++ Code optimization

A

Amod

hi all,
Kindly suggest some tips to optimize the C++ code for higher speed.

regards,
Amod
 
B

benben

Amod said:
hi all,
Kindly suggest some tips to optimize the C++ code for higher speed.

regards,
Amod

Don't confuse the compiler it'll do the optimization for ye.

Regards,
Ben
 
H

Heinz Ozwirk

Amod said:
hi all,
Kindly suggest some tips to optimize the C++ code for higher speed.

Don't do it until your program is completed. If it turns out, that it is
really too slow, find out which part of the program really is the
bottleneck. Don't guess, but measure the speed of the various parts of the
program. Once you know where the program spends most of its time, you might
find out how to improve that part or ask others about it. But remember to
repeat your tests for each compiler you will be using in the future, even
for each future version of your current compiler, for each (version of) OS
and even for different hardware.

And don't forget the guy, who was very proud that he improved a loop, where
his program spent more than 90% of its time, only to find out that it was
the system's idle loop.

Heinz
 
I

Ivan Vecerina

: Kindly suggest some tips to optimize the C++ code for higher speed.

Optimization is more about (application-specific) algorithms
than about line-by-line code tuning.

Of course there are some general advice, like avoiding unnecessary
object copies, calling reserve() on a vector, etc.

Why don't you post a code segment, or describe an algorithm, whose
performance is critical for your application ?
This would allow the group to give you concrete advice.


hth -Ivan
 
D

David

Hello Amod,

hi all,
Kindly suggest some tips to optimize the C++ code for higher speed.

regards,
Amod

Also consider the choices make as you program. Sometimes we know
where bottlenecks may be and other tmes they appear in suprising
places. You'll have to know your tools and measure its performance.
This is usually done after the fact since it is difficult to
gauge the performance of something that doesn't exist. There are
exceptions though.

Consider a large sort or data extraction problem. For small data
sets the method might not be very important as it doesn't affect
the speed that much. Larger data sets we often do need to worry.
You need to choose the right solution for a problem. Communcations
are another good example where how you choose to have products
talk to one another can make a huge difference.

Please remember that speed is often not enough. Correct comes
first. There are some problems where an exact predictable answer
is not needed, but hopefully you know when those methods can be
used.

David
 
F

Frederick Gotham

Amod posted:
hi all,
Kindly suggest some tips to optimize the C++ code for higher speed.


Simplest thing to do is bring your laptop on the train -- that way all
programs will run at least 150km/h faster.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top