Skip to content

Commit

Permalink
Merge pull request #128 from nschloe/perf-counter
Browse files Browse the repository at this point in the history
use perf_counter everywhere
  • Loading branch information
nschloe authored Oct 1, 2021
2 parents 3179f61 + 8c2dcb9 commit 183003e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: ["3.7", "3.8", "3.9", "3.10-dev"]
steps:
- uses: actions/setup-python@v2
with:
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = perfplot
version = 0.9.10
version = 0.9.11
author = Nico Schlömer
author_email = nico.schloemer@gmail.com
description = Performance plots for Python code snippets
Expand All @@ -22,6 +22,7 @@ classifiers =
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Topic :: Software Development
Topic :: Utilities
keywords =
Expand All @@ -34,7 +35,6 @@ package_dir =
packages = find:
install_requires =
dufte >= 0.2.20
importlib_metadata;python_version<"3.8"
matplotlib
numpy
rich
Expand Down
10 changes: 0 additions & 10 deletions src/perfplot/__about__.py

This file was deleted.

10 changes: 1 addition & 9 deletions src/perfplot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
from .__about__ import __version__
from ._main import bench, live, plot, save, show

__all__ = [
"__version__",
"bench",
"plot",
"show",
"save",
"live",
]
__all__ = ["bench", "plot", "show", "save", "live"]
68 changes: 35 additions & 33 deletions src/perfplot/_main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from __future__ import annotations

import io
import time
import timeit
from typing import Callable, List, Optional, Union
from typing import Callable

try:
# Python 3.8+
Expand Down Expand Up @@ -55,11 +57,11 @@ def _auto_time_unit(time_s: float) -> str:
class PerfplotData:
def __init__(
self,
n_range: List[int],
n_range: list[int],
timings_s,
flop,
labels: List[str],
xlabel: Optional[str],
labels: list[str],
xlabel: str | None,
):
self.n_range = np.asarray(n_range)
self.timings_s = timings_s
Expand All @@ -70,9 +72,9 @@ def __init__(
def plot( # noqa: C901
self,
time_unit: str = "s",
relative_to: Optional[int] = None,
logx: Union[str, bool] = "auto",
logy: Union[str, bool] = "auto",
relative_to: int | None = None,
logx: str | bool = "auto",
logy: str | bool = "auto",
):
if logx == "auto":
# Check if the x values are approximately equally spaced in log
Expand Down Expand Up @@ -232,9 +234,9 @@ def __next__(self):
# 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()
t0_ns = time.perf_counter_ns()
val = kernel(data)
t1_ns = time.time_ns()
t1_ns = time.perf_counter_ns()
t_ns = t1_ns - t0_ns

if t_ns == 0:
Expand Down Expand Up @@ -323,16 +325,16 @@ def _b(data, kernel: Callable, repeat: int):

def live(
setup: Callable,
kernels: List[Callable],
kernels: list[Callable],
n_range: npt.ArrayLike,
labels: Optional[List[str]] = None,
xlabel: Optional[str] = None,
labels: list[str] | None = None,
xlabel: str | None = None,
target_time_per_measurement: float = 1.0,
max_time: Optional[float] = None,
equality_check: Optional[Callable] = np.allclose,
max_time: float | None = None,
equality_check: Callable | None = np.allclose,
show_progress: bool = True,
logx: Union[str, bool] = "auto",
logy: Union[str, bool] = "auto",
logx: Literal["auto"] | bool = "auto",
logy: Literal["auto"] | bool = "auto",
):
if labels is None:
labels = [k.__name__ for k in kernels]
Expand Down Expand Up @@ -441,15 +443,15 @@ def callback():


def bench(
kernels: List[Callable],
n_range: List[int],
setup: Optional[Union[Callable, List[Callable]]] = None,
flops: Optional[Callable] = None,
labels: Optional[List[str]] = None,
xlabel: Optional[str] = None,
kernels: list[Callable],
n_range: list[int],
setup: Callable | list[Callable] | None = None,
flops: Callable | None = None,
labels: list[str] | None = None,
xlabel: str | None = None,
target_time_per_measurement: float = 1.0,
max_time: Optional[float] = None,
equality_check: Optional[Callable] = np.allclose,
max_time: float | None = None,
equality_check: Callable | None = np.allclose,
show_progress: bool = True,
):
if labels is None:
Expand Down Expand Up @@ -509,9 +511,9 @@ def callback():
def plot(
*args,
time_unit: str = "s",
logx: Union[str, bool] = "auto",
logy: Union[str, bool] = "auto",
relative_to: Optional[int] = None,
logx: Literal["auto"] | bool = "auto",
logy: Literal["auto"] | bool = "auto",
relative_to: int | None = None,
**kwargs,
):
out = bench(*args, **kwargs)
Expand All @@ -526,9 +528,9 @@ def plot(
def show(
*args,
time_unit: str = "s",
relative_to: Optional[int] = None,
logx: Union[bool, Literal["auto"]] = "auto",
logy: Union[bool, Literal["auto"]] = "auto",
relative_to: int | None = None,
logx: bool | Literal["auto"] = "auto",
logy: bool | Literal["auto"] = "auto",
**kwargs,
):
out = bench(*args, **kwargs)
Expand All @@ -545,9 +547,9 @@ def save(
transparent=True,
*args,
time_unit: str = "s",
logx: Union[bool, Literal["auto"]] = "auto",
logy: Union[bool, Literal["auto"]] = "auto",
relative_to: Optional[int] = None,
logx: bool | Literal["auto"] = "auto",
logy: bool | Literal["auto"] = "auto",
relative_to: int | None = None,
**kwargs,
):
out = bench(*args, **kwargs)
Expand Down

0 comments on commit 183003e

Please sign in to comment.