Web app for wall-clock profiling, growth-curve fitting, and learning content around how a single function scales (Python, Java, C++).
| Area | Command |
|---|---|
| Backend | From time_complexity_analyzer/: pip install -r requirements.txt, then python manage.py migrate and python manage.py runserver |
| Frontend | From time_complexity_analyzer/frontend/: npm install, then npm start |
| Tests | Backend: python manage.py test and/or pytest time_complexity_analyzer/analyzer. Frontend: npm test in frontend/ |
| Docker API | Build/run using time_complexity_analyzer/Dockerfile.backend (Python 3.12 image; JDK + g++ included for Java/C++ harness) |
Environment variables for Django live in time_complexity_analyzer/time_complexity_analyzer/settings.py (e.g. DJANGO_SECRET_KEY). Use a real secret in production.
The UI calls Django under /api/.... Those routes exist on the API service only.
- On the static site build, set
REACT_APP_API_URLto your API’s public origin, e.g.https://your-time-complexity-api.onrender.com(no/apisuffix). Seetime_complexity_analyzer/frontend/.env.production.example. - Rebuild the static site so Create React App inlines the variable (build-time only).
- Keep the web/API service running.
- Async analysis jobs store state in Django’s LocMem cache, which is not shared between Gunicorn workers. This repo’s
Dockerfile.backenduses--workers 1so polling/api/analyse-code/async/<id>/does not randomly 404. If you raise worker count, use Redis (or another shared cache) asCACHES['default']instead ofLocMemCache.
If REACT_APP_API_URL is missing, production builds default the API base to the static site’s origin; POST /api/analyse-code/... then hits the CDN and often returns 404. You can also set window.__TCA_API_BASE__ before the app bundle loads (see frontend/src/components/Axios.js).
- API: Django + Django REST Framework, Gunicorn in Docker.
- UI: React (CRA), MUI, Framer Motion, Recharts.
- Analysis: SciPy least-squares fitting, optional tree-sitter grammars for richer Java/C++ static loop hints when those packages are installed (see
requirements.txt).
CI runs Python 3.12 (see .github/workflows/ci-pipeline.yml).
- Header: centered floating “pill” (glass) with primary nav, workspace label, quick search (⌘/Ctrl+K), theme toggle, and auth.
- Footer: same floating pill treatment for copyright and links.
- Background: light animated complexity-themed glyphs (respects reduced-motion).
The Time Complexity Analyzer is a tool for code profiling, designed to measure runtime and provide insights into the performance of functions. While the tool approximates the time complexity of functions, its accuracy is limited due to the inherent challenges of data fitting and model simplification.
- Precise Runtime Measurement:
- Tracks execution time for each line of code.
- Provides the total runtime of functions.
- Profiling Features:
- Outputs detailed runtime logs for in-depth performance evaluation.
- Highlights performance bottlenecks in functions.
- Approximates the time complexity of functions using fitted mathematical models.
- Limitations:
- The approximations may not always reflect the actual complexity, especially for functions with edge cases or unusual input distributions.
- Relies on data fitting, which introduces inaccuracies for complex or nonstandard patterns.
- A repository of algorithms with:
- Definitions and code examples.
- Instructional videos and quizzes to support learning.
- Secure sign-up and login to provide personalized access to profiling data and analysis reports.
- The tool uses instrumentation to insert profiling hooks into the code.
- For each line or function:
- Start and end timestamps are recorded.
- The difference between these timestamps gives the execution time.
- Outputs include:
- Execution time for each individual line of code.
- Total runtime for the entire function.
The tool applies the "least squares method" to fit runtime data to known mathematical models. Here’s how it works:
-
Collect Data:
- The runtime for various input sizes (x_data) and corresponding execution times (y_data) are recorded.
-
Error Function:
- The error between the observed execution times and the model predictions is minimized.
- For a given model f(x, params), the error function is: Error = Σ [y_i - f(x_i, params)]^2
-
Optimization:
- Numerical optimization techniques (e.g., least_squares from scipy.optimize) are used to adjust the parameters of the model until the error is minimized.
-
Model Selection:
- The tool evaluates multiple models (e.g., linear, logarithmic, quadratic) and selects the one with the lowest residual sum of squares (RSS).
- Overly complex models are penalized to avoid overfitting.
Paths below assume screenshots exist under
images/at the repo root. Replace or add assets as the UI evolves.
- Accuracy of Time Complexity Approximation:
- Limited by the quality of data fitting and the assumptions made by the mathematical models.
- Small coefficients or inappropriate constants can lead to misleading results.
- Single-Array Functions:
- Only supports functions with a single array as input.
- External Calls:
- Cannot measure execution time for functions that rely on external calls.
- Better Runtime Modeling:
- Explore advanced optimization methods like robust regression or Bayesian optimization for improved fitting accuracy.
- Enhanced Profiling:
- Add support for functions with multiple input types and external calls.
- Sophisticated Input Handling:
- Improve input generation methods to better reflect real-world scenarios.




