Main Content

Function Stress Complexity

Complexity of internal structure and external connections of a function

Description

The metric Function Stress Complexity (FSC) is a measure of the complexity of the internal structure and external connections of a function. If the internal structure of a function is complex, its FSC is high. If a function calls many other function or is called by many other function, its FSC is high. A function with a high FSC indicates a possible bottleneck in your code base.

Computation Details

For a function foo(), Polyspace® computes FSC using this formula:

FSC = C ⋅ (NcallingNcalls)2

In this formula:

The terms Ncalling and Ncalls represent the complexity of the external connections of foo(), while C represents the complexity of the internal structure of the function. The minimum values of Ncalling and Ncalls are 1. That is, if foo() does not call any other function, Ncalls is 1. If foo() is not called by any other function, Ncalling is 1.

This metric is equivalent to the MISRA software metric Component Stress Complexity.

Examples

expand all

Find the function stress complexity (FSC) of the function processInput() using the formula

FSC = C ⋅ (NcallingNcalls)2

The function has two control flow structures, the for statement and the if statement,leading to a cyclomatic complexity of 3. No function in this code calls processInputs(), so Ncalling is 1. The function processInputs() calls two other functions, so Ncalls is 2. The FSC for processInputs() is given by:

FSC = 3 ⋅ (1⋅2)2 = 12

.

int processInput(int x);
int auxiliaryFunction1(int x);
int auxiliaryFunction2(int x);



int processInput(int x) {
    int result = 0;
    for (int i = 0; i < x; ++i) { 
        if (i % 2 == 0) { 
            result += auxiliaryFunction1(i);
        } else {
            result += auxiliaryFunction2(i);
        }
    }
    return result;
}

Metric Information

Group: Function
Acronym: FSC
HIS Metric: No