{"id":30920406,"url":"https://github.com/henryhale/worstcase","last_synced_at":"2026-01-20T17:32:15.989Z","repository":{"id":310903548,"uuid":"1040269667","full_name":"henryhale/worstcase","owner":"henryhale","description":"🧐 Automatically analyze time and space complexity of JavaScript code without relying on pattern matching","archived":false,"fork":false,"pushed_at":"2025-08-20T23:47:22.000Z","size":65,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-08-20T23:56:49.063Z","etag":null,"topics":["big-o-analysis","bigocomplexity","bigonotation","henryhale","js","space-time-complexity"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/henryhale.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-18T18:00:46.000Z","updated_at":"2025-08-20T23:47:25.000Z","dependencies_parsed_at":"2025-08-20T23:56:53.872Z","dependency_job_id":"760e5fab-4657-4c10-97ac-c47dd6033267","html_url":"https://github.com/henryhale/worstcase","commit_stats":null,"previous_names":["henryhale/worstcase"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/henryhale/worstcase","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henryhale%2Fworstcase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henryhale%2Fworstcase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henryhale%2Fworstcase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henryhale%2Fworstcase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/henryhale","download_url":"https://codeload.github.com/henryhale/worstcase/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henryhale%2Fworstcase/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274395841,"owners_count":25277387,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-09T02:00:10.223Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["big-o-analysis","bigocomplexity","bigonotation","henryhale","js","space-time-complexity"],"created_at":"2025-09-10T01:18:56.885Z","updated_at":"2026-01-20T17:32:15.956Z","avatar_url":"https://github.com/henryhale.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\u003cimg width=\"45\" src=\"https://github.com/henryhale/worstcase/raw/master/public/logo.svg\" /\u003e\n\u003ch1\u003eworstcase\u003c/h1\u003e\n\u003cp\u003eAutomatic time and space complexity analyzer for JavaScript/TypeScript code\u003c/p\u003e\n\u003cp\u003e\n\u003ca href=\"https://www.npmjs.com/package/worstcase\"\u003e\u003cimg alt=\"npm\" src=\"https://img.shields.io/npm/v/worstcase\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/henryhale/worstcase/blob/master/LICENSE.txt\"\u003e\u003cimg alt=\"GitHub\" src=\"https://img.shields.io/github/license/henryhale/worstcase\"\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/worstcase\"\u003e\u003cimg alt=\"npm downloads\" src=\"https://img.shields.io/npm/dm/worstcase\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003c/div\u003e\n\n## Overview\n\nEver wondered if your JS/TS code is secretly harboring a performance monster? `worstcase` is your solution! This powerful tool automatically analyzes your JS/TS code and computes approximate Big O complexity for both time and space through static code analysis.\n\n## Motivation\n\nThe motivation is simple yet ambitious: to bring algorithmic analysis directly into the development workflow. Instead of manually reasoning through loops and recursive calls, or waiting for performance issues to surface in production, this analyzer examines your code structure and provides instant complexity estimates. It's like having a computer science professor looking over your shoulder, but one who never gets tired and works at the speed of light.\n\n## Features\n\n- **Automated Complexity Analysis**: Computes Big O notation for time and space complexity\n- **Block-level Analysis**: Granular complexity computation for each code block\n- **AST-Based Parsing**: Uses Babel parser for accurate TypeScript/JavaScript/JSX code parsing\n- **No Pattern Matching**: Pure algorithmic analysis without relying on pre-known patterns\n- **Conservative Estimates**: Provides reasonable defaults for unknown code\n- **Built-in Method Knowledge**: Knows complexity of basic Array/Object methods\n\n## Live Demo\n\nCheck the Monaco Editor integration demo:\n[View Repo](https://github.com/henryhale/worstcase-monaco-demo) |\n[Launch Demo](https://henryhale.github.io/worstcase-monaco-demo)\n\n## Quick Start\n\n### Installation\n\n```bash\n# npm\nnpm install @babel/parser worstcase\n```\n\nIn a TypeScript project, add `@babel/types`\n\n```bash\nnpm install @babel/types\n```\n\n## Basic Usage\n\n```js\nimport { analyzeComplexity } from \"worstcase\";\n\n// Example: Analyzing a bubble sort implementation\nconst code = `\nfunction bubbleSort(arr) {\n    for (let i = 0; i \u003c arr.length; i++) {\n        for (let j = 0; j \u003c arr.length - 1; j++) {\n            if (arr[j] \u003e arr[j + 1]) {\n                [arr[j], arr[j + 1]] = [arr[j + 1], arr[j]];\n            }\n        }\n    }\n    return arr;\n}\n`;\n\nconst analysis = analyzeComplexity(code);\nconsole.log(analysis.overall.time); // O(n^2)\nconsole.log(analysis.overall.space); // O(1)\n```\n\n## API Reference\n\n### `analyzeComplexity(code: string, options?: Partial\u003cWCOptions\u003e): WCAnalysis`\n\nAnalyzes JavaScript/TypeScript code and returns complexity information.\n\n#### Parameters\n\n| Parameter | Type                              | Description                                  |\n| --------- | --------------------------------- | -------------------------------------------- |\n| `code`    | `string`                          | JavaScript/TypeScript source code to analyze |\n| `options` | `Partial\u003cWCOptions\u003e \\| undefined` | Configure the analyzer                       |\n\n#### Returns: `WCAnalysis`\n\n```typescript\ntype WCOptions = {\n    clean: boolean; // Whether or not to drop coefficients - default: true\n};\n\ninterface WCAnalysis {\n    overall: {\n        time: string; // Overall time complexity (e.g., \"O(n^2)\")\n        space: string; // Overall space complexity (e.g., \"O(1)\")\n    };\n    results: Array\u003c{\n        type: string; // AST node type\n        node: Node; // Babel AST node: from @babel/types\n        location: string; // Code location\n        time: string; // Time complexity\n        space: string; // Space complexity\n    }\u003e;\n}\n```\n\n#### Example Response\n\n```js\n{\n    overall: {\n        time: \"O(n^2)\",\n        space: \"O(1)\"\n    },\n    results: [\n        {\n            type: \"FunctionDeclaration\",\n            location: \"Line 2\",\n            time: \"O(n^2)\",\n            space: \"O(1)\",\n            node: {...}\n        }\n        // ... more results\n    ]\n}\n```\n\n## Limitations\n\nThis tool provides **approximations**, not perfect mathematical analysis. Current limitations:\n\n- **Dynamic behavior**: Cannot analyze runtime-dependent complexity\n- **External dependencies**: Unknown functions assumed to be `O(1)`\n- **Complex algorithms**: May not recognize advanced algorithmic patterns\n- **Halting problem**: Cannot guarantee termination analysis\n\n## Architecture\n\nThe analyzer uses a multi-step approach:\n\n1. **Parsing**: Uses Babel parser to generate Abstract Syntax Tree (AST)\n2. **Traversal**: Visits each AST node with specific complexity rules\n3. **Combination**: Applies mathematical rules for combining complexities\n4. **Simplification**: Reduces to dominant terms in Big O notation\n\n## Use Cases\n\n`worstcase` is perfect for:\n\n- Helping developers understand the performance implications of their code\n- Catching potential performance bottlenecks during development\n- Serving as an educational tool for learning complexity analysis\n- Giving instant feedback without requiring manual calculation\n- Giving real-time complexity hints via IDE integration\n\n## Contributing\n\nThank you for checking out this awesome project.\nContributions are welcome!\n\n**Areas for improvement**:\n\n- **Recursive pattern recognition**: Advanced recurrence relation solving\n\n### Development Setup\n\n1. Install [Node.js](https://nodejs.org) (\u003e=22) and [pnpm](https://pnpm.io/) (\u003e=10)\n2. Clone this repository\n    ```bash\n    git clone https://github.com/henryhale/worstcase.git\n    cd worstcase\n    ```\n3. Install dependencies\n    ```bash\n    pnpm install\n    ```\n4. Run development server\n    ```bash\n    pnpm dev\n    ```\n5. Run tests\n    ```bash\n    pnpm test\n    ```\n6. Build for production\n    ```bash\n    pnpm build\n    ```\n\n## Support\n\nIf you find this project useful, please consider giving it a star ⭐️ on GitHub!\n\n## License\n\nCopyright (c) 2025-present [Henry Hale](https://github.com/henryhale/).\n\nMIT License - see [LICENSE.txt](https://github.com/henryhale/worstcase/blob/master/LICENSE.txt) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenryhale%2Fworstcase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhenryhale%2Fworstcase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenryhale%2Fworstcase/lists"}