[futurebasic] Re: [FB] GOTO efficiency (was [FB] just a little bit over the l

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : October 1999 : Group Archive : Group : All Groups

From: tedd <tedd@...>
Date: Wed, 20 Oct 1999 11:34:25 -0400
--Steve:

>>I ran your code. The GOTO example was the same speed as the LONG IFs, but
>>the CASE version was significantly (~12%) faster than either.
>
>
>Interesting. I was thinking about switching from goto to case
>statements, but maybe I'll hold off to do some additional time
>testing. Thanks.
>
>--Steve


I think that CASE is quicker. -- But you might want to consider using
CALL's. It is another perspective in logic.

I did a test to see if CALL was quicker than CASE and CASE won -- but not
by much. Code follows:

'-- tedd's demo for branching to FN's 1996 --
'------------- use freely -------------------
'---------- program will run "as-is" --------

COMPILE 0,_dimmedVarsOnly

DIM gCasePtr&(10)
END GLOBALS

'================ functions =================
LOCAL FN Case0
END FN

LOCAL FN Case1
END FN

LOCAL FN Case2
END FN

LOCAL FN Case3
END FN

LOCAL FN Case4
END FN

LOCAL FN Case5
END FN

LOCAL FN Case6
END FN

LOCAL FN Case7
END FN

LOCAL FN Case8
END FN

LOCAL FN Case9
END FN

LOCAL FN Case10
END FN

'add as many additional function as needed

'============ init case pointers ===========
LOCAL FN initCasePtr
  gCasePtr&(0)  = @FN Case0
  gCasePtr&(1)  = @FN Case1
  gCasePtr&(2)  = @FN Case2
  gCasePtr&(3)  = @FN Case3
  gCasePtr&(4)  = @FN Case4
  gCasePtr&(5)  = @FN Case5
  gCasePtr&(6)  = @FN Case6
  gCasePtr&(7)  = @FN Case7
  gCasePtr&(8)  = @FN Case8
  gCasePtr&(9)  = @FN Case9
  gCasePtr&(10) = @FN Case10
  'add as many additional pointers as needed
END FN

'================ init window ==============
LOCAL FN initWindow
  WINDOW #1,"Test Window",(0,0)-(400,400),_doc
  PRINT
  PRINT " One hundred thousand case jumps."
  PRINT
END FN

'================ test call ================
LOCAL FN testCall
  DIM i&, f&
  DIM start&, finish&

  start& = FN TICKCOUNT
  FOR i& = 0 TO 100000
    f& = gCasePtr&(RND(10))
    CALL f&
  NEXT
  finish& = FN TICKCOUNT

  PRINT finish& - start&;" ticks required for CALL pointer."
  PRINT
END FN

'================ test select ===============
LOCAL FN testSelect
  DIM i&, f&
  DIM start&, finish&

  start& = FN TICKCOUNT
  FOR i& = 0 TO 100000
    f& = gCasePtr&(RND(3))
    SELECT f&
      CASE 0
        FN Case0
      CASE 1
        FN Case1
      CASE 2
        FN Case2
      CASE 3
        FN Case3
      CASE 4
        FN Case4
      CASE 5
        FN Case5
      CASE 6
        FN Case6
      CASE 7
        FN Case7
      CASE 8
        FN Case8
      CASE 9
        FN Case9
      CASE 10
        FN Case10
    END SELECT
  NEXT
  finish& = FN TICKCOUNT

  PRINT finish& - start&;" ticks required for SELECT/CASE."
  PRINT
END FN

'=================== main ====================

DIM a$

FN initCasePtr
FN initWindow
FN testCall
FN testSelect

INPUT" Enter anything to end";a$
END


___________________________________________________________________
<mailto:tedd@...>	               http://sperling.com/