What are complexity metrics?

Measuring how convoluted code is, typically cyclomatic or cognitive complexity per function.

By Cláudia FernandesUpdated

Cyclomatic complexity counts independent paths through a function; cognitive complexity weights that by how hard the structure is for a human to follow. Both are proxies for how likely code is to hide a defect and how painful it will be to test.

Complexity is most useful as a trend and as a gate ('no new function above this threshold') rather than as a score to chase. Absolute numbers vary too much between languages and problem domains to compare across teams.

What to look for

  • Which metric is used, and whether the threshold is configurable
  • Function-level reporting rather than only file or repository averages
  • Whether complexity can fail a build or only appear on a dashboard
  • Trend tracking over time, which is more useful than a snapshot

Best 9 code quality, security and code review tools with complexity metrics

Every tool in the directory whose documentation covers this, 6 fully and 3 partially. Full support is shown first. Shown in a random order that changes on every visit, so no tool gets an advantage from its position.

Support is not the same as parity, since some implementations are narrower in scope, gated to a higher plan tier, or maintained only for existing customers. The note under each tool is what its own documentation describes.

FAQ

What are complexity metrics?

Measuring how convoluted code is, typically cyclomatic or cognitive complexity per function.

How many tools in the directory offer complexity metrics?

9 of the 20 tools in this directory offer complexity metrics, 6 fully and 3 partially:

Support is not the same as parity, since some implementations are narrower in scope, gated to a higher plan tier, or maintained only for existing customers. The note under each tool is what its own documentation describes.

What should you check when comparing tools with complexity metrics?

Four things:

  • Which metric is used, and whether the threshold is configurable
  • Function-level reporting rather than only file or repository averages
  • Whether complexity can fail a build or only appear on a dashboard
  • Trend tracking over time, which is more useful than a snapshot