Home

cyclomatic

Cyclomatic complexity, often referred to simply as cyclomatic, is a software metric that quantifies the complexity of a program's control flow. Introduced by Thomas J. McCabe in 1976, the metric captures the number of linearly independent paths through a program's source code and is commonly interpreted as an indicator of testability, maintainability, and risk.

Calculation can be done from a control flow graph (CFG) or by simple counting of decision points.

Interpretation: Lower values suggest simpler, more maintainable code and easier testing; higher values imply more paths

Limitations: The metric focuses on control flow and not on data complexity, readability, or runtime performance.

See also: control flow graph; software metric; testability.

In
a
CFG,
M
equals
E
−
N
+
2P,
where
E
is
the
number
of
edges,
N
the
number
of
nodes,
and
P
the
number
of
connected
components.
In
practice,
developers
often
use
the
rule
that
M
equals
the
number
of
decision
points
plus
one;
decisions
include
if,
while,
for,
case
statements,
and
catch
branches.
Different
languages
or
tools
may
treat
certain
constructs
differently,
but
the
overall
principle
remains.
to
exercise
in
tests
and
a
greater
risk
of
defects.
Cyclomatic
complexity
is
frequently
used
to
identify
refactoring
targets
and
to
estimate
the
minimum
number
of
test
cases.
It
can
be
affected
by
coding
style,
language
features,
and
can
be
inflated
without
actual
complexity.
It
should
be
used
alongside
other
measures
of
quality,
such
as
size,
coupling,
and
cohesion.