From 9f07e1bdace44282fe7cb2c596e26edc4347558c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Sat, 21 Aug 2021 10:31:37 +0200 Subject: [PATCH 1/3] better error message for div by 0 --- src/perfplot/_main.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/perfplot/_main.py b/src/perfplot/_main.py index 04f781d..e321ebb 100644 --- a/src/perfplot/_main.py +++ b/src/perfplot/_main.py @@ -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 From cc2c1808b4216db79a44eb07c171ada0cab337b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Sat, 21 Aug 2021 10:32:28 +0200 Subject: [PATCH 2/3] apply prettier --- .github/ISSUE_TEMPLATE/bug_report.md | 1 + .github/ISSUE_TEMPLATE/feature_request.md | 2 +- .github/workflows/ci.yml | 24 ++++++++++---------- README.md | 27 ++++++++++++++++------- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 5dbb023..f168632 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -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 ``` diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 0091ac9..6c379b3 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -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. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f6b8c03..2079884 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,10 +3,10 @@ name: ci on: push: branches: - - main + - main pull_request: branches: - - main + - main jobs: lint: @@ -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' }} diff --git a/README.md b/README.md index 0753529..eba60ea 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 + + ```python perfplot.live( # ... ) ``` + live 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: + + ```python out = perfplot.bench( # same arguments as above (except the plot-related ones, like time_unit or log*) @@ -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). From 82c806a0a9acb71baa2b1f2a532c8693fee8c510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Sat, 21 Aug 2021 10:32:50 +0200 Subject: [PATCH 3/3] version bump --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 3af792d..3c88a71 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = perfplot -version = 0.9.9 +version = 0.9.10 author = Nico Schlömer author_email = nico.schloemer@gmail.com description = Performance plots for Python code snippets