#OPTIMIZE metastatement  

Purpose

Choose the optimization which should be applied to your program.

Syntax

#OPTIMIZE CODE [ON | OFF]

#OPTIMIZE {SIZE | SPEED}

Remarks

The #OPTIMIZE metastatement is used to tell the compiler your preferences in regards to the optimization of generated code.  You can specify optimization for either execution speed or smaller code size.

The first form of the directive (CODE) tells the compiler whether unreferenced code should be removed from the compiled program to minimize the executable file size.  This option defaults to ON as there are few reasons to disable it (other than curiosity as to the effectiveness).  Regardless of the compiled module type (SLL, DLL, or EXE), PowerBASIC removes every unneeded:

1

Sub

2

Function

3

FastProc

4

Method

5

Property

6

String Literal

7

Numeric Literal

8

Static Link Library

Extraction is always performed on a procedure basis, not an entire class.  If you have a CLASS with 50 Methods, but only one is ever called, the other 49 are removed entirely.  This level of granularity is particularly important with your personal code library of general purpose functions.  You can include them all, and PowerBASIC will use just the minimum necessary.  If you generate a log file (using the /L command line option), a list of the extracted procedures, classes, and SLL modules is provided.

The second form of the directive (SIZE/SPEED) tells the compiler whether you want additional optimization for execution speed or smaller total code size.  If not used, the default is to choose faster code speed.

If you choose the SPEED option, one of the primary actions of the compiler is to align heavily used code sections on an address boundary which is most beneficial to the CPU/FPU.

In some cases, the speed of looping mechanisms (FOR/NEXT, DO/UNTIL...) can be improved by as much as 100%, and occasionally even more.

Restrictions

#OPTIMIZE SIZE | SPEED can only be executed once and must precede all executable code.  If #OPTIMIZE is omitted, the default condition is #OPTIMIZE SPEED.

See also

#ALIGN, ASM ALIGN