[Oberon] Numeric CASE vs IF THEN ELSE Performance
Andreas Pirklbauer
andreas_pirklbauer at yahoo.com
Sun Jun 10 12:04:39 CEST 2018
> If you compile this example on your implementation you
> will be able to compare the code generated by each.
>
> If you look at the disassembler listing you will see that
> another CASE benefit (particularly useful in embedded
> systems) is that it uses significantly less code space
> than IF THEN ELSE as long as the selections are not
> too sparse. The total code generated for each version
> of the Soundex procedures is:
>
> IF-THEN-ELSE: 420 Bytes
> CASE: 240 Bytes
Thx. That’s a helpful hint. Unfortunately my compiler (so far) only
implements the "jump-table technique", so it does not fare well (in
terms of code-space requirements) in cases where the sparseness
of values in the case-label range is high, as outlined in [1].
A proper comparison with your technique (using a modified BR
instruction) would probably have to implement some of the other
techniques suggested in [1], such as the search tree (effectively
leading to a modern version of the paper in the process..).
But your numbers are appealing indeed!
-ap
[1] http://bernd-oppolzer.de/CaseStmts.pdf
("The implementation of Case Statements in Pascal”)
More information about the Oberon
mailing list