FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

FB II COMPILER

Consider speed (I)



The code for LONG IF vs IF/THEN is so close to being identical that it makes little difference what is selected. Many other factors in conditionals take more time than this comparison. The minor difference seems to be that IF/THEN uses a slower JMP instruction where LONG IF uses a faster BEQ or BNE. My tests show that LONG if is a little over 1% faster than IF/THEN. (Not a big deal.)

STAZ ~)~


I got curious & did some time-testing on my own. Results weren't quite what I'd expected, so I'm posting this for general interest. I did this in a rough & dirty way, so code just went like this:

RANDOM

count1& = 0
stoptime& = FN TICKCOUNT + 60
DO
  number = RND(100)
  LONG IF number = 2 OR number = 3
    okay = 1
  XELSE
    okay = 2
  END IF
  count1& = count1& + 1
  newtime& = FN TICKCOUNT
UNTIL newtime& > stoptime&

.... and then the same thing w/ three other structures:

IF number = 2 OR number = 3 THEN okay = 1 ELSE okay = 2

SELECT number
  CASE 2,3
    okay = 1
  CASE ELSE
    okay = 2
END SELECT

SELECT
  CASE number = 2 OR number = 3
    okay = 1
  CASE ELSE
    okay = 2
END SELECT

On average, I got about the same 1% difference favoring LONG IF over IF (but individual runs varied). What surprised me was that CASE number = 2 OR number = 3 was consistently a hair _faster_ than LONG IF... and SELECT NUMBER was generally the fastest of all.
---
SELECT CASE always pushes a long onto the stack for each comparison, then popes it off at the END SELECT. (That's why you can't exit a SELECT CASE in the middle.)

I'm pretty sure that his long int is pushed whether or not there is a variable on the select line.

-STAZ ~)~


There is something that makes a really big difference tho.

POKE @t$,0

Is a _lot_ faster than...

t$ = ""

-STAZ ~)~