Is it better / faster to use IF statements or a Case statement? I intend on using many statements and for some reason I want to think that case is faster but not sure.
you could put the two types into a program and check the CNT timer at the beginning and the end and figure out the difference between the two.
My guess would also be that the CASE command is faster especially when a significant number of conditions are checked. I would also imagine CASE would use less memory than IFs.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!
Spin CASE is very clumsy. It is also limited to 64 cases ... you end up mixing IF and CASE then. If you want to see how it behaves, use BSTC or Homespun for listings and a debugger.
IF/ELSEIF is worst case: 8032 cycles best case: 1200 cycles
CASE is worst case: 6224 cycles best case: 1280 cycles
And the difference is 8 longs in memory.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!
Comments
My guess would also be that the CASE command is faster especially when a significant number of conditions are checked. I would also imagine CASE would use less memory than IFs.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--Steve
Propeller Tools
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
IF/ELSEIF is worst case: 8032 cycles best case: 1200 cycles
CASE is worst case: 6224 cycles best case: 1280 cycles
And the difference is 8 longs in memory.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
April, 2008: when I discovered the answers to all my micro-computational-botherations!