Click here to Skip to main content
16,004,927 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionThe peculiarities of reality : leaner but not faster ? Pin
GJBR29-May-09 10:30
GJBR29-May-09 10:30 
AnswerRe: The peculiarities of reality : leaner but not faster ? Pin
David Crow29-May-09 10:58
David Crow29-May-09 10:58 
GeneralRe: The peculiarities of reality : leaner but not faster ? Pin
GJBR29-May-09 11:10
GJBR29-May-09 11:10 
AnswerRe: The peculiarities of reality : leaner but not faster ? Pin
BobInNJ29-May-09 11:14
BobInNJ29-May-09 11:14 
GeneralRe: The peculiarities of reality : leaner but not faster ? Pin
GJBR29-May-09 11:42
GJBR29-May-09 11:42 
AnswerRe: The peculiarities of reality : leaner but not faster ? Pin
Stuart Dootson29-May-09 13:14
professionalStuart Dootson29-May-09 13:14 
AnswerRe: The peculiarities of reality : leaner but not faster ? Pin
Joe Woodbury29-May-09 13:29
professionalJoe Woodbury29-May-09 13:29 
AnswerRe: The peculiarities of reality : leaner but not faster ? Pin
Luc Pattyn29-May-09 13:40
sitebuilderLuc Pattyn29-May-09 13:40 
Hi,

I did a lot of performance analysis on different processors (mostly for embedded systems) including Intel's x86, but not AMD, and lots of C compilers.

My overall conclusion is there are a lot of factors some of which are difficult to control; one of them is code alignment (the address of the first instruction in a loop being at a multiple of 8 or 16 bytes).

Furthermore there is the issue of instruction scheduling: the CPU has different functional units, some in multiple quantities, and depending on minor details, the instructions get dispatched to some or other units, yielding better or worse performance. Adding an instruction may well lead to a faster piece of code.

The bigger issues however are inside the compiler itself; with standard optimization it should:
1. keep values in registers when there are very few involved (here only i and j);
2. figure out the loop does nothing useful and can be discarded;
3. if the net result of the loop would be some final value (i=UINT_MAX), then it should just assign that, but not in the current case since i and j are dead, their value is not used when the loop is done.
4. and for a real loop, with some body, it should consider "loop unroll".

So my advice is:
- start looking at the compiler switches, make sure you use a normal level of optimization (most of the time I apply several switches, the defaults aren't well chosen if you ask me);
- compare compilers for the kind of code that is most relevant to your app;
- only then start looking at the microscopic level. And get ready for a long learning curve.

Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.

Questionimage in picture control not displayed properly after moving Pin
dumnbncool29-May-09 10:06
dumnbncool29-May-09 10:06 
Questionurgent help Pin
ramina sen29-May-09 8:18
ramina sen29-May-09 8:18 
AnswerRe: urgent help Pin
David Crow29-May-09 8:28
David Crow29-May-09 8:28 
GeneralRe: urgent help Pin
ramina sen29-May-09 8:33
ramina sen29-May-09 8:33 
GeneralRe: urgent help Pin
Cedric Moonen29-May-09 8:51
Cedric Moonen29-May-09 8:51 
GeneralRe: urgent help Pin
CPallini29-May-09 8:58
mveCPallini29-May-09 8:58 
GeneralRe: urgent help Pin
krmed29-May-09 10:17
krmed29-May-09 10:17 
RantRe: urgent help Pin
Michael Schubert29-May-09 12:43
Michael Schubert29-May-09 12:43 
GeneralRe: urgent help Pin
Jim Crafton29-May-09 8:38
Jim Crafton29-May-09 8:38 
AnswerRe: urgent help Pin
Wes Aday29-May-09 9:22
professionalWes Aday29-May-09 9:22 
QuestionWriting a Smart OnPaint Routine Pin
BobInNJ29-May-09 7:15
BobInNJ29-May-09 7:15 
AnswerRe: Writing a Smart OnPaint Routine Pin
CPallini29-May-09 7:39
mveCPallini29-May-09 7:39 
GeneralRe: Writing a Smart OnPaint Routine Pin
BobInNJ29-May-09 9:30
BobInNJ29-May-09 9:30 
QuestionRe: Writing a Smart OnPaint Routine Pin
David Crow6-Nov-09 17:23
David Crow6-Nov-09 17:23 
AnswerRe: Writing a Smart OnPaint Routine Pin
CPallini7-Nov-09 11:23
mveCPallini7-Nov-09 11:23 
GeneralRe: Writing a Smart OnPaint Routine Pin
Michael Dunn30-May-09 18:44
sitebuilderMichael Dunn30-May-09 18:44 
GeneralRe: Writing a Smart OnPaint Routine Pin
BobInNJ31-May-09 4:13
BobInNJ31-May-09 4:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.