Code Complexity Analyzer
Approximate Cyclomatic Complexity, Nesting Depth, and Function Count.
A quick complexity estimate for a code snippet
Code Complexity Analyzer gives you three rough measurements for a block of code: an approximate cyclomatic complexity score, the deepest level of curly-brace nesting, and the number of functions. Cyclomatic complexity counts the independent paths through code, and a high number usually means a function is hard to read, test and change safely. This tool is meant for a fast first look at a snippet, not for replacing a full static-analysis suite.
Getting a reading
- Paste JavaScript, PHP or C++-style code into the Input Data box. Press Sample if you want a small example to try, and Clear to reset.
- Press Process Now. If the box is empty you will see an error asking for code.
- Read the four result tiles: Cyclomatic Complexity, Max Nesting Depth, Total Functions and Maintainability.
- Use Copy or Download if you want the text of the result as result.txt.
How the numbers are calculated
Before counting, the tool strips comments and string contents so that a word inside a message does not count. It then adds up the keywords if, for, while, case and catch, each question mark and each && or || operator, and adds one for the entry path. Functions are counted as occurrences of the word function plus arrow symbols. Nesting depth is the highest number of open curly braces at any point. The built-in sample, with an if, a for and another if nested three levels deep, scores a complexity of 4, a depth of 3 and one function.
The Maintainability tile is simple: it shows Good when complexity is 10 or below and High above that, so High is a warning that the code is complex.
Practical uses
- Checking whether a long function you inherited deserves splitting into smaller ones.
- Comparing the before and after of a refactor to see whether branching really dropped.
- Giving students a concrete way to see how extra conditions add paths.
- Spotting deeply nested blocks during a quick code review.
Limitations worth knowing
This is a text-pattern estimate, not a parser. Indentation-based languages such as Python have no braces, so depth will read as zero. PHP foreach is not matched by the for pattern, and switch, else and do are not counted on their own. Question marks in optional chaining or nullish operators are counted as ternaries, and every function shape other than the function keyword or an arrow is missed. Treat the figures as a guide, and score whole files with caution because the count covers everything you paste.
Related Tools