A VSCode extension that analyzes functions in JavaScript/TypeScript files and inserts a comment above each one estimating its time complexity in Big O notation.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Big O for VSCode is a Visual Studio Code extension that analyzes JavaScript and TypeScript files and adds an estimated Big O time complexity comment above each function. This helps developers quickly assess the computational cost of their functions during development.
✨ Features
Detects and analyzes function definitions (function, arrow functions).
Estimates time complexity using a basic heuristic:
O(1) – No loops detected
O(n) – One loop or loop-like expression
O(n^2) – Nested or multiple loops detected
O(2^n) – Recursive functions detected
Inserts a vs code lens like // Complexity: O(n) above the function.
⚠️ Note: This extension uses a simple static analysis technique and does not perform full control-flow or data-flow analysis. Use results as rough estimates only.
🎥 Demo
Before:
function sum(arr) {
let total = 0;
for (let i = 0; i < arr.length; i++) {
total += arr[i];
}
return total;
}
After running Analyze Function Complexity:
// Complexity: O(n)
function sum(arr) {
let total = 0;
for (let i = 0; i < arr.length; i++) {
total += arr[i];
}
return total;
}
📎 Sample
🚀 Usage
Open a JavaScript or TypeScript file.
Open the Command Palette (Ctrl+Shift+P or Cmd+Shift+P on macOS).
Run Analyze Function Complexity.
The extension will analyze the open file and insert a complexity comment above each function.
🔮 Next Steps
Planned enhancements for future versions include:
Multi-language support:
✅ JavaScript / TypeScript (current)
🟡 Python: Detect def functions and analyze for, while, map, list comprehensions, etc.
🟡 Go: Parse func declarations and loops (for, range).