Measurement of McCabe Metrics with Testwell CMT++ and CMTJava (Code Complexity Measures Tools)Purpose and OriginCyclomatic complexity (also referred as program complexity or McCabe´s complexity) is the most widely used member of a class of static software metrics. It may be considered a broad measure of soundness and confidence for a program.The cyclomatic complexity has been introduced by Thomas McCabe in 1976. It measures the number of linearly-independent paths through a program module. The McCabe complexity is one of the more widely-accepted software metrics, it is intended to be independent of language and language format. Interpreting McCabe MetricsMcCabe's Cyclomatic number v(G) shows the complexity of the flow of control through a piece of code.v(G) is the number of conditional branches in the flowchart. v(G) = 1 for a program consisting of only sequential statements. For a single function; v(G) is one less than the number of conditional branching points in the function. When dynamic testing is concerned, the cyclomatic number v(G) is one of the most important complexity measures. The cyclomatic number of a function should be less than 15. If a function has a cyclomatic number of 15, there are at least 15 (but probably more) execution paths through it. A reasonable upper limit Cyclomatic number of a file is 100. How McCabe Metrics are calculated with CMT++McCabe Cyclomatic number v(G) is calculated on (member) function definitions and on class/struct declarations. It is also calculated on the entire source file.Each if-statement introduces a new branch to the program and therefore increases v(G) by one. It should be noted that v(G) is insensitive to unconditional branches like goto-, return- and break-statements although they surely increase complexity. In CMT++ the branches generated by conditional compilation directives are also counted to v(G). Even if conditional compilation directives do not add branches to the control flow of the executable program, they increase the complexity of the program file that the user sees and edits. In summary, the following language constructs increase the cyclomatic number by one: if (...), for (...), while (...), case ...:, catch (...), &&, ||, ?, #if, #ifdef, #ifndef, #elif. further information about Testwell Complexity Measures Tools: last updated: 05.06.2010 © 2006-2010 Testwell Oy / Verifysoft Technology GmbH |