sujithcp / dotnetperls-controls

Automatically exported from code.google.com/p/dotnetperls-controls
1 stars 0 forks source link

Bug in http://dotnetperls.com/Content/Reorder-If.aspx #3

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hello again,

i'm refering to this piece of code:
[...]
else if (i < 1000)
[...]
else if (i < 100)

If i'm not mistaken, the i < 100 case is supposed to be impossible to occur
since it was already handled by i < 1000. I don't see any better way to
handle this other than moving the i < 100 case in front of i < 1000.

This also affects the performance results slightly. But since the loop
counter is > 2000 in almost all cases anyway, the impact is probably very
small.

Kind regards,
mafutrct.

Original issue reported on code.google.com by mafutr...@googlemail.com on 5 Dec 2008 at 7:32

GoogleCodeExporter commented 8 years ago
Thank you for bug #2! 

You are absolutely correct that the i < 100 will never be reached. The numbers 
are likely 
still close if I were to remove it, unless something else with the pipeline/IL 
code 
affects the loop instructions.

Solution: I switched the two IF statements, and inserted a note that says the 
benchmark 
results are not 100% accurate for the example.

The important part of the article is that the code should do the most important 
stuff 
first usually.

Will upload it soon.

Original comment by allen....@gmail.com on 6 Dec 2008 at 12:39