[Oberon] Numeric CASE vs IF THEN ELSE Performance

Chris Burrows chris at cfbsoftware.com
Sat Jun 16 15:08:31 CEST 2018


> From: Oberon [mailto:oberon-bounces at lists.inf.ethz.ch] On Behalf Of J
> rg
> Sent: Saturday, 16 June 2018 8:15 PM
> To: ETH Oberon and related systems
> Subject: Re: [Oberon] Numeric CASE vs IF THEN ELSE Performance
> 
> For the special case of Soundex, neither IF-THEN nor CASE are perfect
> as we don t want to execute statements per character 

Well, yes, but that is a discussion for another day. The subject of this discussion is "Numeric CASE vs IF THEN ELSE Performance". If you are interested in "The most efficient way to implement the Soundex algorithm" you might well find it here:

https://www.rosettacode.org/wiki/Soundex
 
> 
> BTW: the runtime behaviour of the IF implementation can be optimized
> a little bit by rearranging the different IFs / ORs by taking the
> letter frequency into account. (vowels: 49%, dental-mute: 13%,
> guttural: 12%, nasal: 9%, labial: 7%, dental-fricative: 6%, palatal:
> 4%).
> The code size can shrink a little by using an ELSE to combine the
> eight gutturals.
> 

Agreed. It is always possible to optimise an IF-THEN-ELSE sequence that has different probabilities of selection. However, there may be other reasons why you might want to order the choices in a particular way. 

With a CASE statement you can order the selections in the most natural way without being forced to use a particular sequence because of efficiency concerns.

That reminds me of one of my favourite cartoons (Frank and Ernest). He was boasting that he had made it easier to find streets by putting them in alphabetic order ;-)

  Fifth Street
  First Street
  Fourth Street
  Second Street
  Third Street

Regards,
Chris Burrows
CFB Software
http://www.astrabe.com




More information about the Oberon mailing list