Skip to content

Commit

Permalink
Merge pull request #124 from nschloe/prevent-div-by-0
Browse files Browse the repository at this point in the history
Prevent div by 0
  • Loading branch information
nschloe committed Aug 21, 2021
2 parents 70cf167 + 82c806a commit 2640357
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 24 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ A minimal code example that reproduces the problem would be a big help if you ca

**Diagnose**
I may ask you to cut and paste the output of the following command.

```
pip freeze | grep perfplot
```
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Feature request
about: Suggest an idea for this project
title: "[REQUEST]"
labels: Needs triage
assignees: ''
assignees: ""
---

Consider posting in https://github.com/nschloe/perfplot/discussions for feedback before raising a feature request.
Expand Down
24 changes: 12 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: ci
on:
push:
branches:
- main
- main
pull_request:
branches:
- main
- main

jobs:
lint:
Expand All @@ -25,13 +25,13 @@ jobs:
matrix:
python-version: [3.7, 3.8, 3.9]
steps:
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- uses: actions/checkout@v2
- name: Test with tox
run: |
pip install tox
tox -- --cov perfplot --cov-report xml --cov-report term
- uses: codecov/codecov-action@v1
if: ${{ matrix.python-version == '3.9' }}
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- uses: actions/checkout@v2
- name: Test with tox
run: |
pip install tox
tox -- --cov perfplot --cov-report xml --cov-report term
- uses: codecov/codecov-action@v1
if: ${{ matrix.python-version == '3.9' }}
27 changes: 19 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ testing snippets with input parameters (e.g., the size of an array) and plotting
results.

For example, to compare different NumPy array concatenation methods, the script

```python
import numpy as np
import perfplot
Expand Down Expand Up @@ -47,29 +48,35 @@ perfplot.show(
# flops=lambda n: 3*n, # FLOPS plots
)
```

produces

![](https://nschloe.github.io/perfplot/concat.svg) | ![](https://nschloe.github.io/perfplot/relative.svg)
| --- | --- |
| ![](https://nschloe.github.io/perfplot/concat.svg) | ![](https://nschloe.github.io/perfplot/relative.svg) |
| -------------------------------------------------- | ---------------------------------------------------- |

Clearly, `stack` and `vstack` are the best options for large arrays.

(By default, perfplot asserts the equality of the output of all snippets, too.)

If your plot takes a while to generate, you can also use

<!--pytest-codeblocks:skip-->

```python
perfplot.live(
# ...
)
```

<img alt="live" src="https://nschloe.github.io/perfplot/live.gif" width="40%">

with the same arguments as above. It will plot the updates live.

Benchmarking and plotting can be separated. This allows multiple plots of the same data,
for example:

<!--pytest-codeblocks:skip-->

```python
out = perfplot.bench(
# same arguments as above (except the plot-related ones, like time_unit or log*)
Expand All @@ -80,28 +87,32 @@ out.save("perf.png", transparent=True, bbox_inches="tight")

Other examples:

* [Making a flat list out of list of lists in Python](https://stackoverflow.com/a/45323085/353337)
* [Most efficient way to map function over numpy array](https://stackoverflow.com/a/46470401/353337)
* [numpy: most efficient frequency counts for unique values in an array](https://stackoverflow.com/a/43096495/353337)
* [Most efficient way to reverse a numpy array](https://stackoverflow.com/a/44921013/353337)
* [How to add an extra column to an numpy array](https://stackoverflow.com/a/40218298/353337)
* [Initializing numpy matrix to something other than zero or one](https://stackoverflow.com/a/45006691/353337)
- [Making a flat list out of list of lists in Python](https://stackoverflow.com/a/45323085/353337)
- [Most efficient way to map function over numpy array](https://stackoverflow.com/a/46470401/353337)
- [numpy: most efficient frequency counts for unique values in an array](https://stackoverflow.com/a/43096495/353337)
- [Most efficient way to reverse a numpy array](https://stackoverflow.com/a/44921013/353337)
- [How to add an extra column to an numpy array](https://stackoverflow.com/a/40218298/353337)
- [Initializing numpy matrix to something other than zero or one](https://stackoverflow.com/a/45006691/353337)

### Installation

perfplot is [available from the Python Package
Index](https://pypi.org/project/perfplot/), so simply do

```
pip install perfplot
```

to install.

### Testing

To run the perfplot unit tests, check out this repository and type

```
tox
```

### License

This software is published under the [GPLv3 license](https://www.gnu.org/licenses/gpl-3.0.en.html).
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = perfplot
version = 0.9.9
version = 0.9.10
author = Nico Schlömer
author_email = [email protected]
description = Performance plots for Python code snippets
Expand Down
8 changes: 6 additions & 2 deletions src/perfplot/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,17 @@ def __next__(self):
# and the time for gauging how many more repetitions are to be done. If the
# initial time doesn't exceed the target time, append as many repetitions as
# the first measurement suggests. If the kernel is fast, the measurement
# with one repetition only can be somewhat off, but most of the time it's
# good enough.
# with one repetition only can be somewhat off because the CPU needs to spin
# up first. The actual times are only reached after a few hundred
# nanoseconds of computation. Most of the time it's okay though.
t0_ns = time.time_ns()
val = kernel(data)
t1_ns = time.time_ns()
t_ns = t1_ns - t0_ns

if t_ns == 0:
raise RuntimeError("Measured 0 ns for a function call. Try again?")

if self.equality_check:
if k == 0:
reference = val
Expand Down

0 comments on commit 2640357

Please sign in to comment.