Skip to content

Commit 84fecbb

Browse files
ENH: added pytest benchmark tests; initial (#737)
1 parent 6a659b9 commit 84fecbb

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

benchmarks/pytest_benchmark/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# dpnp/benchmarks/pytest_benchmark/
2+
3+
## Prerequisites
4+
* pytest >= 6.1.1
5+
* pytest-benchmark >= 3.4.1
6+
7+
8+
## Running benchmark tests
9+
```bash
10+
pytest benchmarks/ --benchmark-json=results.json
11+
```
12+
Running tests and saving the current run into `STORAGE`, see [1]
13+
```bash
14+
pytest benchmarks/ --benchmark-json=results.json --benchmark-autosave
15+
```
16+
17+
## Creating `.csv` report
18+
```bash
19+
pytest-benchmark compare results.json --csv=results.csv --group-by='name'
20+
```
21+
22+
## Optional: creating histogram
23+
Note: make sure that `pytest-benchmark[histogram]` installed
24+
```bash
25+
# example
26+
pip install pytest-benchmark[histogram]
27+
pytest -vv benchmarks/ --benchmark-autosave --benchmark-histogram
28+
pytest-benchmark compare .benchmarks/Linux-CPython-3.7-64bit/* --histogram
29+
```
30+
31+
## Advanced running example
32+
```
33+
pytest benchmarks/ --benchmark-columns='min, max, mean, stddev, median, rounds, iterations' --benchmark-json=results.json --benchmark-autosave
34+
pytest-benchmark compare results.json --csv=results.csv --group-by='name'
35+
```
36+
37+
38+
[1] https://pytest-benchmark.readthedocs.io/en/latest/usage.html
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
# cython: language_level=3
3+
# -*- coding: utf-8 -*-
4+
# *****************************************************************************
5+
# Copyright (c) 2016-2020, Intel Corporation
6+
# All rights reserved.
7+
#
8+
# Redistribution and use in source and binary forms, with or without
9+
# modification, are permitted provided that the following conditions are met:
10+
# - Redistributions of source code must retain the above copyright notice,
11+
# this list of conditions and the following disclaimer.
12+
# - Redistributions in binary form must reproduce the above copyright notice,
13+
# this list of conditions and the following disclaimer in the documentation
14+
# and/or other materials provided with the distribution.
15+
#
16+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26+
# THE POSSIBILITY OF SUCH DAMAGE.
27+
# *****************************************************************************
28+
29+
import pytest
30+
31+
import dpnp
32+
import numpy as np
33+
34+
ROUNDS=30
35+
ITERATIONS=4
36+
37+
NNUMBERS=2**26
38+
39+
@pytest.mark.parametrize("function", [dpnp.random.beta, np.random.beta],
40+
ids=["dpnp", "numpy"])
41+
def test_beta(benchmark, function):
42+
result = benchmark.pedantic(target=function, args=(4.0, 5.0, NNUMBERS,),
43+
rounds=ROUNDS, iterations=ITERATIONS)
44+
45+
46+
@pytest.mark.parametrize("function", [dpnp.random.exponential, np.random.exponential],
47+
ids=["dpnp", "numpy"])
48+
def test_exponential(benchmark, function):
49+
result = benchmark.pedantic(target=function, args=(4.0, NNUMBERS,),
50+
rounds=ROUNDS, iterations=ITERATIONS)
51+
52+
53+
@pytest.mark.parametrize("function", [dpnp.random.gamma, np.random.gamma],
54+
ids=["dpnp", "numpy"])
55+
def test_gamma(benchmark, function):
56+
result = benchmark.pedantic(target=function, args=(2.0, 4.0, NNUMBERS,),
57+
rounds=ROUNDS, iterations=ITERATIONS)
58+
59+
60+
@pytest.mark.parametrize("function", [dpnp.random.normal, np.random.normal],
61+
ids=["dpnp", "numpy"])
62+
def test_normal(benchmark, function):
63+
result = benchmark.pedantic(target=function, args=(0.0, 1.0, NNUMBERS,),
64+
rounds=ROUNDS, iterations=ITERATIONS)
65+
66+
67+
@pytest.mark.parametrize("function", [dpnp.random.uniform, np.random.uniform],
68+
ids=["dpnp", "numpy"])
69+
def test_uniform(benchmark, function):
70+
result = benchmark.pedantic(target=function, args=(0.0, 1.0, NNUMBERS,),
71+
rounds=ROUNDS, iterations=ITERATIONS)

0 commit comments

Comments
 (0)