Skip to main content

A local-first profiling tool to benchmark and compare DSA solution efficiency.

Project description

DSA Profiler

dsa-profiler-rishad — A local-first, production-grade profiling framework for benchmarking Data Structures and Algorithms solutions with precision timing, memory tracking, persistent history, and empirical Big-O complexity prediction.


Features

  • High-Precision Benchmarking — Uses hardware-level system counters (time.perf_counter) with multi-iteration tracking and median runtime calculation to filter out OS process jitter.
  • Peak Memory Tracking — Integrates tracemalloc to capture the exact maximum byte footprint consumed by an algorithm during execution.
  • Persistent History — Serverless sqlite3 data layer automatically initializes a hidden .dsa_profile_history.db file in your workspace to preserve performance states across runs.
  • Optimization Delta Engine — Computes exact improvement shifts between successive approaches with color-coded rich tables showing runtime speedups or regression warnings.
  • Empirical Big-O Analyzer — Runs solutions over variable input sizes $N$ using a Pure-Python OLS Linear Regression engine to predict time complexities: $O(1)$, $O(\log N)$, $O(N)$, $O(N \log N)$, $O(N^2)$.

Installation

Requires Python >= 3.8.

pip install dsa-profiler-rishad

Usage

Comparative Solution Tracking

Track runtime and memory shifts across different iterations of an optimization cycle:

import time
from dsa_profiler import profile_dsa

@profile_dsa(problem_id="two-sum", run_name="brute-force", iteration=3)
def solve_via_brute():
    time.sleep(0.1)  # Simulate nested loop overhead
    return "done"

@profile_dsa(problem_id="two-sum", run_name="hash-map-optimized", iteration=3)
def solve_via_map():
    time.sleep(0.01)  # Simulate high-speed lookup
    return "done"

if __name__ == "__main__":
    solve_via_brute()
    solve_via_map()

Big-O Complexity Estimation

Empirically isolate the asymptotic complexity profile of an algorithm over expanding dataset sizes:

import time
from dsa_profiler import profile_big_o

@profile_big_o(n_range=[100, 500, 1000, 2000])
def simulate_linear_growth(n):
    for i in range(n):
        pass
    time.sleep(n * 0.00001)

if __name__ == "__main__":
    simulate_linear_growth()

How It Works

Optimization Delta

When consecutive approaches are registered under the same problem_id, the system retrieves the preceding run from the database and computes:

$$\Delta \text{Time} = \left( \frac{\text{Time}{\text{previous}} - \text{Time}{\text{current}}}{\text{Time}_{\text{previous}}} \right) \times 100$$

A positive result signals a Speedup (green), a negative result triggers a Regression Warning (red).

Big-O Curve Fitting

The analyzer profiles execution time across a scaling range of $N$, transforms inputs into linearized spaces, and applies the Pearson Correlation Coefficient to each transformation:

$$R = \frac{n\sum xy - (\sum x)(\sum y)}{\sqrt{\left[n\sum x^2 - (\sum x)^2\right]\left[n\sum y^2 - (\sum y)^2\right]}}$$

The complexity model with the highest $R^2$ (closest to 1.0) is selected as the predicted asymptotic bound.


Project Structure

dsa_profiler/
├── src/
│   └── dsa_profiler/
│       ├── __init__.py      # Package API exports
│       ├── core.py          # Decorator-based execution interceptors
│       ├── storage.py       # SQLite persistence layer
│       ├── reporter.py      # Analytics engine and rich UI output
│       └── analyzer.py      # OLS regression and Big-O engine
├── tests/
│   └── demo.py              # Sandbox execution suite
├── pyproject.toml           # Package distribution metadata
└── README.md

License

This project is open-source software licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dsa_profiler_rishad-0.1.2.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dsa_profiler_rishad-0.1.2-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file dsa_profiler_rishad-0.1.2.tar.gz.

File metadata

  • Download URL: dsa_profiler_rishad-0.1.2.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.0

File hashes

Hashes for dsa_profiler_rishad-0.1.2.tar.gz
Algorithm Hash digest
SHA256 3c06cac00a67e5b6d536339c6ae3995ca4e78c83f160c64a4fc0aa0720ddae0a
MD5 1350185422aa69455cebfb199fc2235c
BLAKE2b-256 6656ed0e881e0c0e9c6ca08df822398bff82c702f52c86a49c073eb2bd9655a4

See more details on using hashes here.

File details

Details for the file dsa_profiler_rishad-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for dsa_profiler_rishad-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 81e35319aed10bed71324131b937740ae45e9aeb4463b4610e330e8a47bd9928
MD5 5e9db5dbc8b3ae98600fb11e6eae5f05
BLAKE2b-256 591b045dc06813c9537d8134bec8f4d2f5f7c3ab70af69b2c542b315057ffe7f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page