#pragma execution_frequency

Purpose

Marks program source code that you expect will be either very frequently or very infrequently executed.

When optimization is enabled, the pragma is used as a hint to the optimizer.

Syntax

Read syntax diagramSkip visual syntax diagram
>>-#--pragma--execution_frequency--(--+-very_low--+--)---------><
                                      '-very_high-'      

Parameters

very_low
Marks source code that you expect will be executed very infrequently.
very_high
Marks source code that you expect will be executed very frequently.

Usage

Use this pragma in conjunction with an optimization option; if optimization is not enabled, the pragma has no effect.

The pragma must be placed within block scope, and acts on the closest point of branching.

Examples

In the following example, the pragma is used in an if statement block to mark code that is executed infrequently.
int *array = (int *) malloc(10000);

if (array == NULL) {
    /* Block A */
    #pragma execution_frequency(very_low)
    error();
}
In the next example, the code block Block B is marked as infrequently executed and Block C is likely to be chosen during branching.
if (Foo > 0) {
    #pragma execution_frequency(very_low)
    /* Block B */
    doSomething();
} else {
    /* Block C */
    doAnotherThing();
}
In this example, the pragma is used in a switch statement block to mark code that is executed frequently.
while (counter > 0) {
    #pragma execution_frequency(very_high)    	
    doSomething();
}	/* This loop is very likely to be executed.    */

switch (a) {
    case 1:
        doOneThing();
        break;
    case 2:
        #pragma execution_frequency(very_high)	
        doTwoThings();	
        break;
    default:
        doNothing();
}    /* The second case is frequently chosen.   */
The following example shows how the pragma must be applied at block scope and affects the closest branching.
int a;
#pragma execution_frequency(very_low)
int b;

int foo(boolean boo) {
    #pragma execution_frequency(very_low)
    char c;

    if (boo) {
        /* Block A */
        doSomething();
        {
            /* Block C */
            doSomethingAgain();
            #pragma execution_frequency(very_low)
            doAnotherThing();
        }
    } else {
        /* Block B */
        doNothing();
    }

    return 0;
}

#pragma execution_frequency(very_low)