Average Cyclomatic Complexity is one of the source-code metrics Understand computes across 17+ languages — browse them in the GUI, export and track them, or script them with the Python API.
Average Cyclomatic Complexity
API ID: AvgCyclomaticLanguages: Ada, Basic, C#, C++, Fortran, Java, Jovial, Pascal, Python, Rust, VHDL, Web
Targets: Architectures, Classes, Files, Modules, Packages, Project
Average cyclomatic complexity for all nested functions or methods.
For example:
class SayHello {
public:
SayHello() {}
void printHello();
};
void SayHello::printHello() {
switch (i) {
...
}
}
void cyclomaticDemo() {
...
}
int func(); // declared here, not defined - excluded from aggregates
int main() {
...
}
SayHello(), printHello(), cyclomaticDemo(), and main() have Cyclomatic Complexity of 1, 4, 10, and 2. func() is only declared, not defined, so it isn't counted. For the SayHello class, the average is (1 + 4) / 2 = 2.5, rounded to 3. For the whole file (sample.cpp), the average is (1 + 4 + 10 + 2) / 4 = 4.25, rounded to 4.
See Sum and Max Cyclomatic Complexity for the other aggregations.
- Ada: Project, File, Package
- Basic: Project, File, Module, Class, Struct
- C#: Project, File, Class, Struct
- C++: Project, File, Class, Struct, Union
- Fortran: Project, File
- Java: Project, File, Class, Interface
- Jovial: Project, File
- Pascal: Project, File, Class, Interface, Compunit
- Python: Project, File, Class
- Rust: Project, File
- VHDL: Project, File, Architecture
- Web: Project, File, PHP Class, PHP Interface
- For projects and architectures, this metric must also be enabled from "Project Configuration/Metrics/Projects and Architectures" with the "Show aggregated function metrics" option.
- The cyclomatic metric used is configured from "Project Configuration/Metrics/Complexity". This metric results from having "Count each decision in a multi-way-decision structure" on and having "Count logical conjuctions (OR) and logical and (AND)" off. Checking "Show all available cyclomatic complexity metric variants" will also enable the metric.