⚡ Complexity Analyzer
Real-time time & space complexity analysis for C/C++ functions — powered by GitHub Copilot.
Created by bhaimicrosoft
Features
🔍 Auto-Analysis on Cursor Placement
Simply place your cursor inside any C/C++ function and the extension automatically detects the enclosing function, extracts its full body, and displays a detailed complexity analysis in the sidebar — no manual selection needed.
✏️ Live Updates as You Code
The analysis updates in real-time as you edit your function. Every time you modify the code, the extension re-analyzes the function with a smart debounce (1.2s) so results stay current without flooding requests.
🌳 Recursion Tree Visualization
For recursive functions, the extension goes beyond simple Big-O notation:
- Shows the recurrence relation (e.g.,
T(n) = 2T(n/2) + O(n))
- Displays the recursion depth
- Renders an ASCII recursion tree with a small example input to help you visualize how calls branch out
Example recursion tree output:
fib(5)
/ \
fib(4) fib(3)
/ \ / \
fib(3) fib(2) fib(2) fib(1)
/ \
fib(2) fib(1)
💡 Better Solution Suggestions
If a more optimal algorithm exists for the same problem, the extension will:
- Compare current vs. optimized complexity
- Explain the improved approach
- Provide complete, ready-to-use C++ code with a one-click Copy button
Results appear in a dedicated Complexity Analyzer panel in the activity bar (left sidebar) — no popups or interruptions to your workflow.
How It Works
| Trigger |
What Happens |
| Cursor in a function |
Auto-detects the function, analyzes complexity, shows results in sidebar |
| Edit code inside a function |
Re-analyzes automatically after 1.2s of inactivity |
| Switch between functions |
Sidebar updates to show the new function's analysis |
Ctrl+Shift+C |
Analyze the currently selected code |
Ctrl+Shift+Alt+C |
Analyze the entire file |
| Right-click context menu |
Choose "Analyze Complexity (Selection)" or "Analyze Complexity (Entire File)" |
Analysis Output
For each function, you get:
📊 twoSum
## Time Complexity
- Best Case: O(1)
- Average Case: O(n)
- Worst Case: O(n)
## Space Complexity
- Auxiliary Space: O(n)
- Total Space: O(n)
## Explanation
The function uses a hash map for O(1) lookups...
## Recursion Analysis
(Recursion tree shown for recursive functions)
## Better Solution
(Optimized code shown if a better approach exists)
Requirements
| Requirement |
Details |
| VS Code |
Version 1.93.0 or later |
| GitHub Copilot |
Installed and signed in with an active subscription |
| GitHub Copilot Chat |
Installed (provides the Language Model API) |
Installation
From VSIX (local)
- Open VS Code
- Press
Ctrl+Shift+P → "Extensions: Install from VSIX..."
- Select the
.vsix file
- Reload VS Code
From Source
cd complexity-analyzer-extension
npm install
npm run compile
# Then press F5 to launch Extension Development Host
Keyboard Shortcuts
| Shortcut |
Action |
Ctrl+Shift+C |
Analyze selected code |
Ctrl+Shift+Alt+C |
Analyze entire file |
Project Structure
complexity-analyzer-extension/
├── media/
│ └── icon.svg # Activity bar icon
├── src/
│ └── extension.ts # Main extension code
├── out/ # Compiled JavaScript output
├── package.json # Extension manifest
├── tsconfig.json # TypeScript config
└── README.md
Known Limitations
- Analysis quality depends on the GitHub Copilot language model
- Very large functions may take a few seconds to analyze
- The recursion tree is ASCII-based (text art) for maximum compatibility
- Currently optimized for C and C++ files (
.c, .cpp, .h, .hpp)
Release Notes
0.1.0
- Dedicated sidebar panel with activity bar icon
- Auto-analyze function under cursor (no selection needed)
- Live re-analysis on code edits with smart debounce
- Recursion tree visualization for recursive functions
- Better solution suggestions with copyable optimized code
- Improved markdown-to-HTML rendering with styled code blocks
- Copy-to-clipboard button on all code blocks
0.0.2
- Initial release with selection and file analysis commands
- Context menu and keyboard shortcuts
License
MIT
Enjoy analyzing! ⚡