benchmark-my-code
A robust, student-proof benchmarking framework designed for education. It bridges the gap between raw execution timing (like timeit) and complex profiling tools, providing a safe, statistically sound environment for comparing algorithmic approaches.
The module's objective is to support learning Python by making it easier to understand both the performance and correctness of code.
Core Workflows
benchmark-my-code supports two main usage patterns:
1. Ad-Hoc Mode (Exploration & Comparison)
Designed for rapid iteration, comparing ideas, or demonstrating a concept with zero friction. You can easily compare multiple implementations using decorators.
from benchmark_my_code import benchit, run_benchmarks
@benchit
def sum_using_string(number):
return sum(int(digit) for digit in str(number))
@benchit
def sum_using_modulo(number):
total = 0
while number > 0:
total += number % 10
number //= 10
return total
if __name__ == '__main__':
# Run all registered functions against varying inputs.
# validate=True ensures all implementations return the exact same result.
run_benchmarks(
variants=[(123,), (456789,), (1234567890,)],
validate=True
)
2. Challenge Mode (Structured Learning)
Designed for university settings or self-guided learning. A "Challenge" is provided by an external learning package and includes hidden reference implementations, test cases, and staged guidance.
from benchmark_my_code import challenge
from bmc_cs101 import SortingChallenges
@challenge(SortingChallenges.sort_level_1)
def my_sort(input_list):
return sorted(input_list)
In this mode, the framework acts as a mentor: it validates the function signature, prevents accidental cheating (e.g., modifying inputs in place), provides staged feedback, and scales absolute timeouts based on the reference implementation's performance to ensure fairness across different hardware.
Features & Pluggable Output
- Correctness Validation: Benchmarks are useless if the code is wrong. The framework supports validating the output of functions, either against each other (consensus) or against a hidden reference.
- Intelligent Profiling: Memory analysis is slower than time profiling. The framework uses adaptive profiling: establishing time stability first, then strategically sampling memory to sketch Big-O trends.
- Pluggable Output: Outputs adapt to the environment: an object for programmatic use, a clean terminal table for CLI, data-frame ready structures for notebooks (matplotlib/seaborn) without forcing heavy dependencies, and JSON for automated grading systems.
For details on how the engine achieves reliable results and handles safety, see ADR.md.
Metadata
Release files for benchmark-my-code 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| benchmark_my_code-0.2.0.tar.gz | 118.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| benchmark_my_code-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 141.4 kB
Release files / benchmark_my_code-0.2.0.tar.gz
| Download URL | benchmark_my_code-0.2.0.tar.gz |
|---|---|
| Size | 118.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4a59a52c2a886789b9e2bc69711c7bd3a42144518c8b317cca77f0fee1f6e6d4
|
|
BLAKE2b-256 checksum How to use checksums |
e32ed55ebb61f2f6e01fc30c6f4b445b56711213052cab0ab903d248d8b5d738
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 5, 2026.
Transparency logRelease files / benchmark_my_code-0.2.0-py3-none-any.whl
| Download URL | benchmark_my_code-0.2.0-py3-none-any.whl |
|---|---|
| Size | 23.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d9d0eeb9e1015508127f6b2cbabba0a6057fe731bbd79da118e88b67eb75e1d2
|
|
BLAKE2b-256 checksum How to use checksums |
a443470e9dd6cebb5fa9e93a30eff6244c4bcb424335f2736786184e332e393f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 5, 2026.
Transparency log