Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arteymix/benchpy
Benchmark Python code
https://github.com/arteymix/benchpy
Last synced: 26 days ago
JSON representation
Benchmark Python code
- Host: GitHub
- URL: https://github.com/arteymix/benchpy
- Owner: arteymix
- License: bsd-3-clause
- Created: 2014-09-01T19:03:43.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-11-28T18:57:33.000Z (about 10 years ago)
- Last Synced: 2024-11-17T18:11:45.339Z (about 1 month ago)
- Language: Python
- Homepage:
- Size: 244 KB
- Stars: 18
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
benchpy
=======
benchpy is a Python utility to benchmark code.Installation
------------
```bash
pip install benchpy
```Usage
-----
Benchmarks are grouped and named. The default group is `None` and the default
name is the name of the function being benchmarked.```python
from benchpy import benchmarked@benchmarked(group='passing', name='')
def function():
pass
```You may also benchmark snippet of code using a context manager, in this case,
you must name your benchmark.```python
from benchpy import benchmarkedwith benchmarked(group='passing', name='passing in a context'):
pass
```Then you can use the `statistics` function to get an overview of the results of
a given function.
```python
from benchpy import benchmarked@benchmarked()
def foobar():
passprint(benchmarked.results('foobar'))
print(benchmarked.statistics('foobar'))
```Examples covering basic usage are providen in the
[examples folder](https://github.com/arteymix/benchpy/tree/master/examples).Results from `results` is stored as a numpy array:
```yaml
[[0.15900000000000003, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0],
[0.15900000000000003, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0],
[0.15900000000000003, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0]]
```You can then apply any data treatment numpy provides, which is practical for
plotting your results.The `statistics` function will compute simple statistics about your result set:
```yaml
# [user time, system time, ...]
max: [0.15900000000000003, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0],
sum: [0.15900000000000003, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0],
avg: [0.15900000000000003, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0],
min: [0.15900000000000003, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0],
med: [0.15900000000000003, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0]
```The fields for each calculation will match those of `resource.getrusage`:
[getrusage documentation](https://docs.python.org/2/library/resource.html#resource.getrusage).`benchmarked` also allow you to define what kind of `rusage` data you want,
defaulted to `RUSAGE_SELF`.```python
@benchmarked(rusage=RUSAGE_BOTH)
def foo():
pass
```The `resource` module is not available in Windows, so only the second column
will contain relevant information.