Cyclomatic Complexity Calculator
Calculate McCabe's cyclomatic complexity from control flow graph edges, nodes, and connected components. Assess code maintainability and testability.
How to Use the Cyclomatic Complexity Calculator
- Enter the number of edges in the control flow graph.
- Enter the number of nodes.
- Enter the number of connected components (usually 1).
- Click Calculate to get complexity and risk level.
使用场景
- •Measuring code complexity for refactoring decisions.
- •Setting complexity thresholds in code review gates.
- •Identifying functions that need unit test coverage.
- •Tracking complexity trends across software releases.
公式
M = E − N + 2P. E = edges, N = nodes, P = connected components. Risk: 1–10 low, 11–20 medium, 21–50 high, >50 very high.
常见问题
What is cyclomatic complexity?
Cyclomatic complexity measures the number of linearly independent paths through code. Higher = more complex and harder to test.
What complexity is acceptable?
1–10 is simple and easy to test. 11–20 is moderate. Above 20 should be refactored. Above 50 is considered untestable.
How does complexity relate to testing?
Cyclomatic complexity equals the minimum number of test cases needed for full branch coverage of a module.