0

Lets simply fantasize and talk about performance.

As I have read the article in about.delphi.com called performance programming, there was interesting paragraphs claiming that Case statement ( in fact I prefer calling it as structure ) is faster than If ; For is faster than While and Repeat, but While is the slowest loop operator. I probably understand why While is the slowest, but ... what about others.

Have you tested / played / experimented or even gained real performance boost if changed, for example, all IF statements to Cases where possible?

Also I would like to talk about other - modified - loop and if statement behaviors in Delphi IDE, but it would be another question.

Shall we start, ladies and gentleman?

2
  • Thanks Lieven for error notification and correction! Commented Jul 8, 2009 at 8:53
  • Please provide a link for the article you mention. I find nothing there named "Performance programming." Commented Jul 8, 2009 at 15:09

3 Answers 3

3

It's very rare when the type of control structure/loop construct do matter. You can't possibly get any reasonable performance increase if you change, say, For loop to While loop. Rather, algorithms do matter.

Sign up to request clarification or add additional context in comments.

Comments

2

I doubt for will be slower in practice than while.

AFAIK, for evaluates the condition one time while while (no pun intended) evaluates the condition every time. Consider following statements

for i = 0 to GettingAmountOfUsersIsTakingALotOfTime do
begin
  ...
end;

i := 0;
while i <= GettingAmountOfUsersIsTakingALotOfTime do
begin
  ...
  Inc(I);
end;

The while statement will be magnitudes of times slower than the if statement.

1 Comment

yes, you are absolutely correct. I did write wrong - I thought the same, but somehow wrote different ;) Anyways - thank you for tip and illustration - I hope it will help othe begginers in Delphi programming ;)
1

This is the best response I've seen to questions like this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.