analyze-complexity
Skill7 starsChanged 15 days agoMITView on GitHub
Use when reviewing or choosing code on a hot path or over user data — estimate Big-O and amortized cost, and decide when O(n²) is a bug versus a style point.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- VelimirMueller/claude-skillsword for word, first seen Nov 1, 2026
Other versions1 project uses a version of this.
Word for word · 1
- VelimirMueller/claude-skills★ 7100% same
Edited · 0
None found.
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository156 other files it gives its agents.
- skills/swift/swiftui-design-principles/AGENTS.mdAGENTS.md
- skills/swift/ios-code-audit/CLAUDE.mdCLAUDE.md
- skills/swift/swift-focusengine-pro/llms.txtllms.txt
- build-llm-seamSkill
- build-mcp-serverSkill
- build-rag-pipelineSkill
- secure-llm-featuresSkill
- set-up-llm-evalsSkill
- build-nextjs-backendSkill
- build-supabase-edge-functionSkill
- configure-backend-testsSkill
- design-http-apiSkill
- harden-backendSkill
- scaffold-fastapi-serviceSkill
- scaffold-go-serviceSkill
- scaffold-hono-serviceSkill
- secure-supabase-rlsSkill
- set-up-backend-authSkill
- set-up-background-jobsSkill
- set-up-databaseSkill
- set-up-nextjs-supabase-authSkill
- set-up-observabilitySkill
- set-up-supabaseSkill
- build-cliSkill
- release-cliSkill
- set-up-dev-toolchainSkill
- audit-securitySkill
- audit-toolchainSkill
- extend-skillsetSkill
- promote-releaseSkill
- set-up-stack-profileSkill
- write-commit-messagesSkill
- write-pull-requestsSkill
- apply-algorithmsSkill
- apply-design-patternsSkill
- apply-design-principlesSkill
- apply-solidSkill
- choose-data-structureSkill
- debug-systematicallySkill
- enforce-dependency-ruleSkill
- refactor-safelySkill
- slice-and-estimateSkill
- write-clean-testsSkill
- write-readable-codeSkill
- clean-frontend-scaffoldingSkill
- configure-accessibilitySkill
- configure-analyticsSkill
- configure-ciSkill
- configure-error-trackingSkill
- configure-lintingSkill
- configure-test-stackSkill
- configure-typescriptSkill
- create-moduleSkill
- optimize-performanceSkill
- scaffold-frontend-projectSkill
- set-up-authSkill
- set-up-design-systemSkill
- set-up-document-headSkill
- set-up-error-boundariesSkill
- set-up-feature-flagsSkill
- The first 60 shown.
The file
Files
Analyze Complexity
Estimates the growth order of code so a review can tell a real performance bug from a style nit. It is the "measure before optimizing" companion to engineering-principles.md.
Growth order
O(1) < O(log n) < O(n) < O(n log n) < O(n²) < O(2ⁿ). A comparison sort cannot beat Ω(n log n).
1. Audit (change nothing)
cat .claude/stack-profile.md 2>/dev/null | head -20
grep -rn "for\|while\|sort\|find\|filter\|map" --include="*.ts" --include="*.rs" --include="*.go" --include="*.py" . 2>/dev/null | head -30Find the loop that depends on the size of user data, and name its order: a nested loop over the same
collection is O(n²); a loop that halves its range is O(log n); a loop that sorts then scans is
O(n log n). Watch for a call inside the loop that hides another loop (a .find inside a for).
2. Decide whether it matters
- The input is bounded (a form with five fields, a fixed set of options) → the order is a style point.
- The input is user data or grows unbounded (rows, messages, search results) → the order is a bug when it
is
O(n²)or worse, or when a linear scan repeats inside a loop (N+1: a query or scan per element, O(n) → O(n²)). - The code is on a hot path (per request, per render) → measure before changing; a trace is the evidence.
3. Distinguish average from worst and amortized
- Average vs worst: quicksort averages
O(n log n)but isO(n²)worst-case on already-sorted input without a good pivot; hash lookup isO(1)average butO(n)worst on a bad hash. - Amortized: a dynamic array's append is
O(1)amortized even though one in every N doubles and costsO(n); the rare cost is spread across the many cheap ones.
Verify
State the order of the changed code, name the input it grows with, and cite the number (a profile, a trace, or the data size) that decided bug-vs-style. A second pass confirms no loop hidden inside the loop.
When to deviate
- Fix a known algorithmic mistake (N+1, quadratic over user data) without a profile — it is a bug, not a guess. See engineering-principles.md.
- Bounded input: optimising it is noise; keep the readable version.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

