Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is faster/most efficient (speed wise) IF or CASE
#21
I c. :*)

:oops:
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#22
I think this will make it even faster.

Code:
qbasicSUB foo()
dumb code
dumb code
dumb code

IF blah = blahblah THEN
   Do something
   EXIT SUB
ELSEIF blah = blahblahblah THEN
   Do somethingelse
   EXIT SUB
   ...
ENDIF

I noticed an increase in speed in my program =P
Reply
#23
Yup, always exiting as soon as done.


I know GOTO is a nono, but I wonder if it wouldn't be possible to gain even more speed by using it.

This is how I have it setup right now:

Code:
qbasicSUB bla ()
do stuff
do stuff
do stuff

call sub.all.the.ifs.are.here ()

do stuff
do stuff
end sub

I wonder if it would be faster like this:
Code:
qbasicSUB bla ()
do stuff
do stuff
do stuff

if nana$ = "bla" then
do stuff
goto end.of.ifs
elseif [...]
[...] imagine a lot of ifs here (nested ofcourse)
end if

end.of.ifs:

do stuff
do stuff
end sub

Is goto faster then calling a sub?
Reply
#24
Definitely goto is faster than calling a SUB because when you call a SUB there are overheads involved where as GOTO doesnt involve that many overheads.
Reply
#25
GOTO is great for speed. And you are an experienced programmer, so GOTO is not a no-no for you.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#26
Quote:Yup, always exiting as soon as done.


I know GOTO is a nono, but I wonder if it wouldn't be possible to gain even more speed by using it.

This is how I have it setup right now:

Code:
qbasicSUB bla ()
do stuff
do stuff
do stuff

call sub.all.the.ifs.are.here ()

do stuff
do stuff
end sub

I wonder if it would be faster like this:
Code:
qbasicSUB bla ()
do stuff
do stuff
do stuff

if nana$ = "bla" then
do stuff
goto end.of.ifs
elseif [...]
[...] imagine a lot of ifs here (nested ofcourse)
end if

end.of.ifs:

do stuff
do stuff
end sub

Is goto faster then calling a sub?

Hey Zire, I agree with Nate (Although I argue with Aga against the virtues of goto)...Goto is a good tool for making a clean exit from a nested loop structure. In your example, I don't think goto should help, because, since the first condition was true, the elsif should behave in the same manner as your goto.

I rarely use it, but like the goto for this structure...

Code:
do  '<---My post has a "do" here!!!
  do
    if condition = true then goto outtahere
  loop
loop
outtahere:
end

rather than:
Code:
do  '<--My post has a "do" here
  do
    if condition = true then outtahere = not false
  loop while not outtahere
loop while not outtahere
end

Edit: EEEKKKK!!!!!!!!! That damn code highlighter is messing with my post....again....can somebody turn that *feature* off???!!!...ok...I removed the "code" flags...to get the code to appear a little bit better...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)