IF or SELECT


Closed Thread
Results 1 to 2 of 2

Thread: IF or SELECT

  1. #1
    Join Date
    Jul 2005
    Posts
    93

    Default IF or SELECT

    whats faster to execute this "IF" statement or this "select" statement? (and why?)

    IF RECADD = 0 THEN outr0
    IF RECADD = 1 THEN outr1 ' if request is for RECADD#1 then goto RECADD#1 routine
    IF RECADD = 2 THEN outr2 ' if request is for RECADD#2 then goto RECADD#2 routine
    IF RECADD = 3 THEN outr3 ' if request is for RECADD#3 then goto RECADD#3 routine
    IF RECADD = 4 THEN outr4 ' if request is for RECADD#4 then goto RECADD#4 routine
    IF RECADD = 5 THEN outr5 ' if request is for RECADD#5 then goto RECADD#5 routine
    IF RECADD = 6 THEN outr6 ' if request is for RECADD#6 then goto RECADD#6 routine

    or

    SELECT CASE RECADD
    CASE 1
    GOTO outr1
    CASE 2
    GOTO outr2
    CASE 3
    GOTO outr3
    CASE 4
    GOTO outr4
    CASE 5
    GOTO outr5
    CASE 6
    GOTO outr6
    ELSE
    END SELECT

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    For things like this, I use a little code timer that I wrote. It uses Timer0 to measure execution time of code snippets.

    Presently, it is designed for use with an 18F8720 running at 20Mhz, but it could be easily modified for other processors or speeds.

    '------------------------------------------------------------------------


    DEFINE OSC 20 ' Set for 20Mhz operation

    DEFINE NO_CLRWDT 1 ' Don't waste cycles clearing WDT
    DEFINE _18F8720 1
    DEFINE HSER_RCSTA 90H
    DEFINE HSER_TXSTA 20H

    DEFINE HSER_CLROERR 1
    DEFINE LOADER_USED 1
    Define USE_LFSR 1

    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 2
    DEFINE ADC_SAMPLEUS 50

    DEFINE I2C_HOLD 1
    DEFINE I2C_SLOW 1


    TRISC = %10111111 ' Hardware serial port on PORTC.7,PORTC.6

    PSPCON = %00000000 ' No PSP
    MEMCON = %10000000 ' No External Memory
    CMCON = %00000111
    ' No Comparator used, turn it off
    TXSTA1.2 = 1
    SPBRG = 129

    INTCON = $80 ' Turn off interrupts

    T0CON = %10001000 ' No Prescaler,16 bit Timer 0

    TimerValue VAR WORD
    RealTime VAR WORD
    OverFlow VAR BYTE
    Prescale VAR BYTE
    DummyVal VAR Byte




    '-------------------------------------------------------------------------------
    ' Put Variables required by program here
    '-------------------------------------------------------------------------------
    Restart:

    '-------------------------------------------------------------------------------
    'Put code to be timed here
    '----------------------------------------------------------------------------



    Time_It:

    TimerValue.LowByte = TMR0L
    TimerValue.Highbyte = TMR0H

    IF INTCON.2 = 1 THEN
    INTCON.2 = 0
    OverFlow = OverFlow + 1
    If OverFlow = 1 THEN
    T0CON = %10000010
    Prescale = 8
    ENDIF
    IF OverFlow = 2 THEN
    HSEROUT ["Execution time too long - choose another prescaler value",13,10]
    ENDIF
    GOTO RESTART
    ENDIF



    HSEROUT ["Execution Time = ",#(TimerValue * Prescale), " Cycles, ",#((TimerValue/5)*Prescale)," Microseconds",13,10,10]
    HSEROUT ["Press any key to restart",13,10]

    HSERIN [DummyVal]
    GOTO Restart

    END
    Charles Linquist

Similar Threads

  1. Sony SIRC IR Issue
    By Ryan7777 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 8th August 2015, 08:10
  2. Multiple "AND"'s in select case?
    By polymer52 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 1st January 2010, 19:10
  3. Code Issue - select case or 'if' issue - not sure why
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 7th October 2007, 08:52
  4. select case question
    By ronjodu in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 12th March 2006, 10:01
  5. Select Case syntax
    By keithdoxey in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 27th September 2005, 19:19

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts