I got two almost same loop, but with remarkable difference in performance, both tested with MSVC2010, on system ~2.4 GHZ and 8GB RAM
Below loop take around 2500 ms to execute
for (double count = 0; count < ((2.9*4/555+3/9)*109070123123.8); count++)
;
And this loop execute in less then 1 ms
for (double count = ((2.9*4/555+3/9)*109070123123.8); count >0; --count)
;
What making such huge difference here? One got post increment and other using pre-increment can it result in such huge difference?
Step1: Assign Value to Variable.Step2: Check If condition is true and Execute Block of CodeStep3: IncrementStep4: Repeat Step2 and Step3. In the first loop you need to calculate the value of expression for every iteration and in second loop you do the calculation only once.