Skip to content

feat: Add "Complexity Estimator" CLI (Stable & Type-Aware) #4

Merged
heikkitoivonen merged 5 commits intoheikkitoivonen:mainfrom
ahmadshajhan:Complexity-Estimator
Feb 2, 2026
Merged

feat: Add "Complexity Estimator" CLI (Stable & Type-Aware) #4
heikkitoivonen merged 5 commits intoheikkitoivonen:mainfrom
ahmadshajhan:Complexity-Estimator

Conversation

@ahmadshajhan
Copy link
Copy Markdown
Contributor

New Feature: Complexity Estimator CLI

This PR adds scripts/estimate_complexity.py, a tool that measures the Big-O time complexity of your Python functions.

Key Capabilities

  • Auto-Detection: Runs functions with increasing input sizes (n=100 to 10000) to identify $O(1)$, $O(n)$, $O(n^2)$, and more.
  • Smart Data Generation: Uses Type Hints (n: int, data: list) to automatically create the right test inputs.
  • Zero Dependencies: Written in pure Python (standard library only).

Usage

python scripts/estimate_complexity.py my_module my_function

large_time = measure_time(lambda: large_list.copy(), iterations=50)

assert is_linear_time(small_time, large_time, self.SIZE_RATIO), (
assert is_linear_time(small_time, large_time, self.SIZE_RATIO, tolerance=5.0), (
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the tolerance changes and I can then accept the PR.

We should think some more about flakiness and address that in a separate, focused change. One option would be to increase the number of iterations.

Also, if you plan to make more PRs in the future, please do one focused change per PR. This current one has several unrelated changes: documentation fixes, new script & tests for it, test flakiness fixes, encoding fixes, uv fixes, and whitespace fixes.

@heikkitoivonen heikkitoivonen self-assigned this Jan 31, 2026
@heikkitoivonen
Copy link
Copy Markdown
Owner

I am going to merge the PR, undo the tolerance changes, and then do some different changes on top to make the tests more reliable.

@heikkitoivonen heikkitoivonen merged commit 5514ea4 into heikkitoivonen:main Feb 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants