User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 425,893 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,973 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 39409 | Replies: 41
Reply
Join Date: Dec 2005
Posts: 3,638
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 22
Solved Threads: 415
Colleague
Salem's Avatar
Salem Salem is offline Offline
void main'ers are DOOMed

Re: C++ Performance Tips

  #41  
Jun 20th, 2008
> 1. In VS 6.0 (on Intel H/W) (are unsigned better?)
So, you pick one specific processor / compiler combination out of the many 10's of processors (or maybe hundreds of variants, or thousands of compilers + flag variations) and decide that proves it?
Interesting it may be, but it's not in my "useful" things to know when it comes to getting the best out of the code.

The whole point of using a HLL is to stop you from having to worry about the minutia of how specific machines handle specific cases, and thus allow you to concentrate on the bigger issues.

Any (let me say it again for the hard of reading, ANY) attempt at performance optimisation before you've finished the program and done some meaningful profiling is a waste of time. Focus your effort on choosing good data structures and algorithms, which will save hours (or months) of computing time, and let the compiler worry about the microseconds.

Your fast loop won't mean squat if you were dumb enough to put it in a bubble sort for example. There isn't an optimiser out there which can spot a bubble sort and decide to replace it with quicksort. That's YOUR job, so do it.

If you're finding your "optimised" code hard to read, then for sure so will the compilers' optimiser, and it will just chicken out and do exactly what you asked for.

Take those ridiculous attempts at swapping variables (without a temp) for example.

What could possibly be wrong with
{ int temp = a ; a = b ; b = temp; }
printf( "%d %d\n", a, b );
Simple, obvious, and more importantly, TRANSPARENT to the optimiser. My recent version of gcc for example optimised this out to (wait for it)
printf( "%d %d\n", b, a ); That's right, the swap is GONE!

An extreme case maybe, but it does illustrate that if the code is clear in it's purpose, then the optimiser may just get rid of it and find another way to get to where you want to be.

With all those swap tricks, the optimiser is left with "Huh?, WTF is that" and you get exactly what you asked for.

Compilers have evolved a lot since the 1980's, so stop recycling all those 1980's tricks. They either don't work, are unnecessary or just make it worse.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
Reply With Quote  
Join Date: Aug 2007
Posts: 202
Reputation: x3mario is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
x3mario's Avatar
x3mario x3mario is offline Offline
Posting Whiz in Training

Re: C++ Performance Tips

  #42  
22 Days Ago
I have picked some ideas here about c++. Thanks gurus.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 7:16 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC