Loop performance

G

GJ

Hi,

I am just querious regarding the performance of the different loops
(do-while, for, while) in "C". Is ther any difference between them
performance wise ...

Regards,
GJ
 
F

Flash Gordon

GJ said:
I am just querious regarding the performance of the different loops
(do-while, for, while) in "C". Is ther any difference between them
performance wise ...

This has been asked many times, and it depends entirely on you compiler.
However, since most compilers are quite good at optimising it is almost
always better to write the code so that it expresses your intent clearly
to your readers (including yourself) since then the code is more likely
to actually *be* correct.

Alternatively, I'm sure I can speed up the ATM you use a great deal.
Admittedly it won't give you the money after deducting it from your
account, but that's not a problem is it, as long as it is fast?
 
P

pete

The loops aren't the same.

for loops and while loops respond
differently to the continue keyword.

for loops and while loops are more interchangable
with each other than they are with do loops.

Sometimes I see code,
where the for loop or while loop control expression,
is preloaded so that the loop will execute at least once.
That's usually a good time to use a do loop.
 
S

SM Ryan

# Hi,
#
# I am just querious regarding the performance of the different loops
# (do-while, for, while) in "C". Is ther any difference between them
# performance wise ...

The primary performance determinant is how often you execute the
innermost loop or function body. That decides the O(fN) efficiency
of the program. Anything is just a linear multiple of that, and
compiled control structures are a very small multiple.
 
G

g.kanaka.raju

GJ said:
Hi,

I am just querious regarding the performance of the different loops
(do-while, for, while) in "C". Is ther any difference between them
performance wise ...

Regards,
GJ


Every thing depends on what code COMPILER generates! Smart compilers
will generate almost similar code for different loops. In assembly, a
loop is nothing but keeping count in a register, decrementing it's
value after each iteration and jumping back.

Regards,
Raju
 
M

Mabden

GJ said:
Hi,

I am just querious regarding the performance of the different loops
(do-while, for, while) in "C". Is ther any difference between them
performance wise ...

Use a profiler, to show exactly how much time you are wasting.

Use a spell-checker, to show exactly how bad your spelling is.

Use a looping construct that exactly matches the problem, to show you
can program.
 

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
474,169
Messages
2,570,920
Members
47,464
Latest member
Bobbylenly

Latest Threads

Top