Cosmos75
Registered User.
- Local time
- Today, 13:35
- Joined
- Apr 22, 2002
- Messages
- 1,281
I have two versions of code with a one difference. Below are the only lines of code that are different.
Why is the second version slower?
The faster version takes anywhere from 66% to 91% of the time the slower version takes to run (based on the total time it took to run several thousand test runs, which I did several times).
One more piece of info on the code that may or may not be useful.
- “Xmultiple ” will never be more than "Limit", therefore the number of times the faster code will loop though the While statement will also never be more than the value of "Limit".
Code:
[COLOR=Green]'-----------------FAST-----------------[/COLOR]
Xmultiple = 0
M = Limit ^ (i - 1)
While Xcurrent > G
Xmultiple = Xmultiple + 1
Xcurrent = Xcurrent - (M)
Wend
[COLOR=Green]'-----------------SLOW-----------------[/COLOR]
M = Limit ^ (i - 1)
Xmultiple = (Xcurrent - G) / M
Xmultiple = CInt(Xmultiple + 0.5) [COLOR=Green]'RoundUP to 0 decimals[/COLOR]
Xcurrent = (Xcurrent - (Xmultiple * M))

The faster version takes anywhere from 66% to 91% of the time the slower version takes to run (based on the total time it took to run several thousand test runs, which I did several times).
One more piece of info on the code that may or may not be useful.
- “Xmultiple ” will never be more than "Limit", therefore the number of times the faster code will loop though the While statement will also never be more than the value of "Limit".
Last edited: