Code

Cyclomatic Complexity Estimator

Estimates cyclomatic complexity per function by counting branch points in real code.

Loading the tool…

Processing happens locally in your browser. What you paste or load is processed by this page and is not uploaded to a server. Nothing is stored unless you use a control that says it stores something, and you can clear anything this site has kept from the privacy page.

How to use this tool

  1. Paste one or more functions.
  2. Select Estimate.
  3. Start at the top of the table — it is sorted with the most complex function first.
  4. Treat anything above 10 as a candidate for splitting, not as a defect.

What complexity estimator does

Cyclomatic complexity counts the independent paths through a function: one, plus one for every branch. It maps directly onto testing effort, because that count is the minimum number of test cases needed to reach every path. A function scoring 25 is not badly written by definition, but it does need twenty-five tests before you can say it works.

This is an estimate, and it says so on every result. It counts branch keywords and logical operators in code that is genuinely code, ignoring anything in a comment or a string, but it has no parser behind it: a compiler-grade tool will disagree at the edges. Use it to find the two functions in a file that need attention, which it does reliably, rather than to defend a number to three decimal places.

Frequently asked questions

It is the count of independent paths through the function: one, plus one for each branch. The practical reading is that it is the minimum number of test cases needed to exercise every path, which is why a function scoring 25 is expensive to verify whether or not it is well written.

It is an estimate and is labelled as one. Branch keywords and logical operators are counted in code that is genuinely code, with comments and strings excluded, but there is no parser behind it, so a tool built on your language’s own AST will disagree at the edges. It is reliable for finding the two functions in a file that need attention.

Common practice is to look at anything above 10 and to treat above 20 as needing to be split. Those are conventions rather than laws — a long switch statement over a list of countries scores badly and is perfectly clear.