View Single Post
Old 11 June 2018, 01:27   #123

Shatterhand's Avatar
Join Date: Jun 2001
Location: Rio de Janeiro / Brazil
Age: 35
Posts: 3,091
Ok, I've made a few tests.

Select..Case seems to be just a series of If..else one after the other. If the first "case" is the right one, it executes faster than the last "case" is the true one (or if there's no case at all).. it's actually a little faster than doing IFs for some reason, but not a lot faster to make a big difference unless you are doing a shitload of them (Still worth using it though - should use it more on my code)

In the other hand, On..Gosub is pretty fast most of the time. If the first subroutine is the selected one it will go a little faster, but then the speed doesnt change if its the second or the thirtieth one being executed. This is *great*

EDIT: Testing on REAL hardware (my 68000 A600 with 2Mb Chip Ram) gives me a lot more random results than on Winuae emulating a 040. Still, the same results more or less, On..Gosub always more or less at the same speed either the second or thirtieth option is the true one, while Select Case is a little faster when it's the first or second option, then it becomes progressively slower.

On..Gosub should be used instead of Select..Case when it's viable and you are dealing with more than 5 possibilities. When the right option was the 5th one or before that one, sometimes Select..Case is faster, sometimes On..Gosub is faster (like I said, it's weirdly too random), but from the 6th possibility onwards, On..Gosub is always faster.

So, when using Select Case, always try to have the more common possibility before the less common ones.

Last edited by Shatterhand; 11 June 2018 at 01:51.
Shatterhand is offline  
Page generated in 0.04137 seconds with 11 queries