Cyclomatic complexity
Cyclomatic complexity is a software metric (measurement) in computational complexity theory. It is used to measure the complexity of a program. It directly measures the number of linearly independent paths through a program’s source code. Cyclomatic complexity is computed using a graph that describes the control flow of the program. The nodes of the graph correspond to the commands of a program. A directed edge connects two nodes if the second command might be executed immediately after the first command. This is done by counting the number of closed loops in the flow graph, and incrementing that number by one. i.e.
M = Number of closed loops + 1
where M = Cyclomatic number.
Let us see an example:
In the above example, the number of closed loops = 2. So Cyclomatic complexity=3.
In general, in order to fully test a module all execution paths through the module should be exercised. This implies a module with a high complexity number requires more testing effort than a module with a lower value since the higher complexity number indicates more pathways through the code. This also implies that a module with higher complexity is more difficult for a programmer to understand since the programmer must understand the different pathways and the results of those pathways.
Advertisement
Categories: Uncategorized