Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Paranoia
#3
Generally speaking, as long as you're not dealing with looping and such, it doesn't matter. For example:

SELECT CASE foo
CASE 1
'let's do lots of stuff
'and some optional stuff that only happens when foo is one
CASE 2
'let's do lots of stuff like above
'and some optional stuff that only happens when foo is two
END SELECT

Verses this:

'Let's do lots of stuff exactly as above
SELECT CASE foo
CASE 1
'we do the optional stuff for case 1
CASE 2
'we do the optional stuff for case 2
END SELECT

In both these situations, we're not going to see any real difference in program speed or performance. We still do the bunch of stuff no matter which branch we take with the SELECT CASE, so there's no savings in performance to come along anywhere. The second method produces less code and is generally easier to keep up with and debug, but performance wise, it's not going to be very different than the first method.

Now, where you *do* see changes in performance is when loops are involved.

FOR I = 1 to 1000
SELECT CASE Foo
CASE 1 'do some stuff if foo is 1
CASE 2 'do some stuff if foo is 2
END SELECT
NEXT

Verses the following:

SELECT CASE foo
CASE 1
FOR I = 1 TO !000
'Do some stuff for when foo is 1
NEXT
CASE 2
FOR I = 1 TO !000
'Do some stuff for when foo is 2
NEXT
END SELECT

In this situation, the second set of code will perform better than the first set of code, even though it's more code to it!! WHY?? Because it's only making that SELECT CASE decision once, whereas the first set of code has to make that decision 1000 different times. Structure here can play a huge part on performance, and is something to keep in mind if your code is running noticeably slower than desired.
Reply


Messages In This Thread
Paranoia - by bartok - 08-13-2022, 03:47 PM
RE: Paranoia - by bplus - 08-13-2022, 04:51 PM
RE: Paranoia - by SMcNeill - 08-13-2022, 04:58 PM
RE: Paranoia - by bartok - 08-13-2022, 08:59 PM
RE: Paranoia - by Kernelpanic - 08-13-2022, 08:16 PM
RE: Paranoia - by Petr - 08-13-2022, 09:16 PM
RE: Paranoia - by bartok - 08-14-2022, 07:28 AM
RE: Paranoia - by TempodiBasic - 08-15-2022, 10:04 PM
RE: Paranoia - by bartok - 08-16-2022, 10:34 AM



Users browsing this thread: 8 Guest(s)