Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IF, CASE, EXECUTE... Which 's Faster????

General Coding

IF, CASE, EXECUTE... Which 's Faster????

by  Gaudalier  Posted    (Edited  )
Evolution: the meaning of 4 and 5 GL. But a High Level Programming Lenguaje NEVER will be as FAST and SMALL as ASSEMBLER Lenguaje, by many reasons. So We are Clarion Programmers: a 4 GL (Dunno if still being 3 GL) we are not responsable for the Optimization of ASSEMBLER code that finally generate Clarion in the Exe's, but for the way we use the High Lenguaje instructions.

So I make some Testing in find the Faster instruccion in CONDITIONAL STATEMENT EXECUTION ESTRUCTURES: [color red]IF, CASE, EXECUTE, CHOOSE, INLIST.[/red] These are all That I know by now.

The BenchMark is base on a 10 Options to look for (All falses), and finally select an 11 Option when there's no matching values. All inclosed in a [/b] [color red]10,000,000[/red][/b] Times LOOP

Here the code:
[/b][color red]IF ESTATEMENT[/red][/b]
Code:
CheckinTime#  = CLOCK()
TRUELIES#     = 69
LOOP 10000000 TIMES
  IF    TRUELIES# = 1
    TRUELIES# = 1
  ELSIF TRUELIES# = 2
    TRUELIES# = 1
  ELSIF TRUELIES# = 3
    TRUELIES# = 1
  ELSIF TRUELIES# = 4
    TRUELIES# = 1
  ELSIF TRUELIES# = 5
  TRUELIES# = 1
  ELSIF TRUELIES# = 6
  TRUELIES# = 1
  ELSIF TRUELIES# = 7
  TRUELIES# = 1
  ELSIF TRUELIES# = 8
  TRUELIES# = 1
  ELSIF TRUELIES# = 9
  TRUELIES# = 1
  ELSIF TRUELIES# = 10
  TRUELIES# = 1
  ELSE
    TRUELIES# = 96
  END
END
MESSAGE('Holding: ' & CLOCK()-CheckinTime# & ' Cent/Second','First Down  !!!!!')

[/b][color red]CASE ESTATEMENT[/red][/b]
Code:
CheckinTime#  = CLOCK()
TRUELIES#     = 69
LOOP 10000000 TIMES
  CASE  TRUELIES#
    OF  1
    TRUELIES# = 1
    OF  2
    TRUELIES# = 2
    OF  3
    TRUELIES# = 3
    OF  4
    TRUELIES# = 4
    OF  5
    TRUELIES# = 5
    OF  6
    TRUELIES# = 6
    OF  7
    TRUELIES# = 7
    OF  8
    TRUELIES# = 8
    OF  9
    TRUELIES# = 9
    OF  10
    TRUELIES# = 10
  ELSE
    TRUELIES# = 96
  END
END
MESSAGE('Holding: ' & CLOCK()-CheckinTime# & ' Cent/Second','First Down  !!!!!')

[/b][color red]EXECUTE ESTATEMENT[/red][/b]
Code:
CheckinTime#  = CLOCK()
TRUELIES#     = 69
LOOP 10000000 TIMES
  EXECUTE TRUELIES#
    TRUELIES# = 1
    TRUELIES# = 2
    TRUELIES# = 3
    TRUELIES# = 4
    TRUELIES# = 5
    TRUELIES# = 6
    TRUELIES# = 7
    TRUELIES# = 8
    TRUELIES# = 9
    TRUELIES# = 10
  ELSE
    TRUELIES# = 96
  END
END
MESSAGE('Holding: ' & CLOCK()-CheckinTime# & ' Cent/Second','First Down  !!!!!')

[/b][color red]CHOOSE ESTATEMENT[/red][/b]
Code:
CheckinTime#  = CLOCK()
TRUELIES#     = 69
LOOP 10000000 TIMES
  TRUELIES# = CHOOSE(TRUELIES#,1,2,3,4,5,6,7,8,9,10,96)
END
MESSAGE('Holding: ' & CLOCK()-CheckinTime# & ' Cent/Second','First Down  !!!!!')

[/b][color red]INLIST ESTATEMENT[/red][/b]
Code:
CheckinTime#  = CLOCK()
TRUELIES#     = 69
LOOP 10000000 TIMES
  TRUELIES# = INLIST(TRUELIES#,'1','2','3','4','5','6','7','8','9','10')
  IF TRUELIES# = FALSE
    TRUELIES# = 96
  END
END
MESSAGE('Holding: ' & CLOCK()-CheckinTime# & ' Cent/Second','First Down  !!!!!')

[color red]STATS:[/color]
Time is in Hundredths of a Sec. Test was made in a Pentium III, 256 RAM & NT 4.0 WorkStation SP 6a, Using C55f ABC. (**** The Small, the Better ****)

[color blue]IF STATEMENT:[/color][color red] -> 35[/color]
[color blue]CASE STATEMENT:[/color][color red] -> 33[/color]
[color blue]EXECUTE STATEMENT:[/color][color red] -> 36[/color]
[color blue]CHOOSE STATEMENT:[/color][color red] -> 8[/color]
[color blue]INLIST STATEMENT:[/color][color red] -> 1619 [/color]

[color red]CONCLUTION:[/color]

Well, at least you're programming a FAST requiring App. like Images and Data process, the Time you save by choosing the CHOOSE statement is not trascendental matters. Finnally the way your [color red]CODE LOOKS LIKE[/color] is order to be the easiest understanding by others or to be corrected by yourself after a long time periods, is the Conditional Statement that MUST TO BE CHOOSEN.


Bye


Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top