Skip to main content

Cyclomatic Complexity Calculator

Paste a function (JavaScript, TypeScript, Python, Java, or Go) to instantly calculate its cyclomatic complexity score, identify every decision point, and get the minimum number of test cases required for full branch coverage.

✓ Per-function CC score + risk level ✓ Decision point list ✓ Min test cases required ✓ No code leaves your browser

Complexity Score

—
No code yet

Decision Points Found

Run analysis to see decision points.

Risk Scale

1–5 Low — simple, easy to test
6–10 Moderate — acceptable, write tests
11–20 High — refactor recommended
21+ Critical — too risky, must refactor
Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

Related Articles

Mar 30, 2026 · 12 min read

Modern TDD in 2026: Test-Driven Development with Vitest, Playwright & AI Copilots

Test-Driven Development has evolved. This practical guide covers modern TDD workflows using Vitest for unit tests, Playwright for E2E, MSW for API mocking, and how AI coding assistants (GitHub Copilot, Claude Code) are changing how we write tests first.

Mar 28, 2026 · 11 min read

Playwright vs Cypress vs Puppeteer 2026: Which Testing Tool Should You Choose?

Playwright vs Cypress vs Puppeteer 2026 — compare feature sets, performance, developer experience, parallel testing, CI costs, and browser support. Find the right E2E testing tool for your stack.

Mar 28, 2026 · 11 min read

Vitest: The Fast Unit Testing Framework for Vite Projects - 2026 Guide

Complete guide to Vitest in 2026: setup, configuration, mocking, coverage, watch mode, and a detailed comparison with Jest to help you decide which testing framework fits your project.

Mar 28, 2026 · 10 min read

Vitest vs Jest vs Mocha: Complete Testing Framework Comparison 2026

A comprehensive comparison of Vitest, Jest, and Mocha for JavaScript and TypeScript projects in 2026. Covers speed benchmarks, configuration, TypeScript support, mocking, code coverage, and migration strategies.

Mar 28, 2026 · 14 min read

Vitest Complete Guide 2026: Fast Unit Testing for Modern JavaScript

Master Vitest in 2026 — the fastest JavaScript testing framework. Learn setup, writing tests, mocking, snapshot testing, coverage, and CI integration with practical code examples.

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$9/mo after trial · Cancel anytime

Want the full toolkit?

Get DevPlaybook Pro

Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →

Frequently Asked Questions

What is cyclomatic complexity?▼

Cyclomatic complexity (CC) measures the number of linearly independent paths through a function's source code. It equals 1 plus the number of decision points: each if, else if, for, while, do, case, catch, &&, ||, and ternary (?) adds 1. A CC of 1–5 is simple; 6–10 is moderate; 11–20 is high and should be refactored; 21+ is unmaintainable.

What risk level is acceptable?▼

McCabe's original guideline: CC ≤ 10 per function is the widely-accepted safe threshold. Many teams use 15 as a practical ceiling. Functions above 20 are considered too risky to modify safely without comprehensive test coverage. The key insight: CC also equals the minimum number of test cases needed to cover all branches.

What decision points does this tool count?▼

This tool counts: if / else if, for / for-of / for-in, while / do-while, switch case / default, catch blocks, logical && and ||, ternary ? operator, and optional chaining ?. (optional chaining). Each adds one independent path through the code.

How do I reduce cyclomatic complexity?▼

Extract complex conditions into named boolean variables. Use early returns (guard clauses) to flatten nested ifs. Split long functions into smaller single-responsibility helpers. Replace if/else chains with lookup tables or strategy patterns. Use Array methods (filter, map, reduce) instead of manual loops with conditions.

Is cyclomatic complexity the same as cognitive complexity?▼

No. Cyclomatic complexity counts structural paths (good for test coverage planning). Cognitive complexity (SonarSource) counts how hard code is to understand — it adds extra weight for nesting depth. A simple flat switch with 10 cases is CC=10 but low cognitive complexity. A deeply nested if-else tree may be CC=5 but high cognitive complexity. Both metrics are useful.