Skip to content

Commit cc2c9a0

Browse files
committed
numpy: parametrize some benchmarks
1 parent e175efe commit cc2c9a0

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
BENCHES := ""
22
BENCHFLAGS :=
33

4+
# To group benchmark output by benchmark, use BENCHFLAGS=--benchmark-group-by=func.
45
python-bench: numpy/*.py
56
pytest --ignore=taco $(BENCHFLAGS) $(BENCHES)
67

numpy/windowing.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,42 @@
22
from scipy.sparse import random
33
import pytest
44

5-
def test_add_sparse_window(benchmark):
5+
def test_add_window(benchmark):
66
dim = 10000
7-
matrix = random(dim, dim, format="csr")
7+
matrix = random(dim, dim, format="csr").todense()
8+
def bench():
9+
x = matrix[1:(dim-1), 1:(dim-1)]
10+
res = x + x
11+
benchmark.pedantic(bench, iterations=10)
812

13+
@pytest.mark.parametrize("dim", [5000, 10000, 20000])
14+
def test_add_sparse_window(benchmark, dim):
15+
matrix = random(dim, dim, format="csr")
916
def bench():
1017
x = matrix[1:(dim-1), 1:(dim-1)]
1118
res = x + x
1219
# Sanity check that this has a similar runtime as taco.
1320
# res = matrix + matrix
1421
benchmark.pedantic(bench, iterations=10)
1522

16-
def test_add_multiple_sparse_windows(benchmark):
17-
dim = 10000
23+
@pytest.mark.parametrize("dim", [5000, 10000, 20000])
24+
def test_add_multiple_sparse_windows(benchmark, dim):
1825
matrix1 = random(dim, dim, format="csr")
1926
matrix2 = random(dim, dim, format="csr")
20-
2127
def bench():
2228
res = matrix1[1:(dim-1), 1:(dim-1)] + matrix2[1:(dim-1), 1:(dim-1)] + matrix1[0:(dim-2), 0:(dim-2)]
2329
benchmark.pedantic(bench, iterations=10)
2430

25-
def test_add_sparse_strided_window(benchmark):
26-
dim = 10000
31+
@pytest.mark.parametrize("dim", [5000, 10000, 20000])
32+
def test_add_sparse_strided_window(benchmark, dim):
2733
matrix = random(dim, dim, format="csr")
2834
def bench():
2935
x = matrix[1:(dim-1):2, 1:(dim-1):2]
3036
res = x + x
3137
benchmark.pedantic(bench, iterations=10)
3238

33-
def test_add_sparse_index_set(benchmark):
34-
dim = 10000
39+
@pytest.mark.parametrize("dim", [5000, 10000, 20000])
40+
def test_add_sparse_index_set(benchmark, dim):
3541
indexes = [i * 2 for i in range(0, dim//2)]
3642
matrix = random(dim, dim, format="csr")
3743
def bench():

0 commit comments

Comments
 (0)