Beautiful and pythonic benchmarks engine.
Project description
true-north
Beautiful and pythonic benchmarks engine for Python code.
Features:
- Follows best practices of benchmarking to produce the most reliable results.
- Detects caching and side-effects.
- Opcodes tracing for reproducble benchmarks.
- 100% type safe.
- Zero dependency.
- Highly configurable.
- Nice and colorful output.
- Ships with CLI to discover and run all benchmarks.
Installation
pytohn3 -m pip install true-north
Usage
import true_north
group = true_north.Group()
@group.add()
def math_sorted(r):
val = [1, 2, 3] * 300
# timer start before entering the loop
# and stops when leaving it
for _ in r:
sorted(val)
# run and print all benchmarks in the group
if __name__ == '__main__':
group.print()
See examples for more examples.
Tracing opcodes
If you run CLI with --opcodes
or call Group.print
with opcodes=True
, the output will also include the number of opcodes executed by the benchmark function. The idea is similar to how benchee counts reductions (function calls) for Erlang code. The difference between measuring execution time and executed opcodes is that the latter is reproducible. There are a few catches, though:
- Different version of Python produce different number of opcodes. Always run benchmarks on the same Python interpreter.
- Tracing opcodes requires true-north to register multiple tracing hooks, which slows down the code execution. It won't affect the timing benchmarks, but it will take more time to run the suite.
- More opcodes doesn't mean slower code. Different opcodes take different time to run. In particular, calling a C function (like
sorted
) is just one opcode. However, if you compare two pure Python functions that don't use call anything heavy, opcodes will roughly correlate with the execution time.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
true-north-0.1.0.tar.gz
(337.2 kB
view details)
Built Distribution
File details
Details for the file true-north-0.1.0.tar.gz
.
File metadata
- Download URL: true-north-0.1.0.tar.gz
- Upload date:
- Size: 337.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.25.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31cedca138be940c0a00b347845bd9473a66a99925b330a28e7c8702c5414e9d |
|
MD5 | bd5129e069983f5ca4d965441cc79f28 |
|
BLAKE2b-256 | 1bca2414f771c0d017e629dcd83e018fed0bff8b4bbd937b04456b311a8557a5 |
File details
Details for the file true_north-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: true_north-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.25.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 348536a94d11f954868f9c424bc72d2bdc637618267793ea869d7526da0e3faa |
|
MD5 | ee3c7a577bf2700b9176ade78b32fc4a |
|
BLAKE2b-256 | b9094ac31ff55fa52d0f618c512dfbbdfb05699e0ef8f1ca64769f32818b5207 |