Skip to content

Commit 8f89f26

Browse files
author
Rohan Yadav
committed
numpy: add benchmarks for individual components of computation for window benchmarks
1 parent c515eb8 commit 8f89f26

File tree

1 file changed

+124
-23
lines changed

1 file changed

+124
-23
lines changed

numpy/windowing.py

+124-23
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,35 @@ def sliceTensor(tensor, dim, config):
2929
else:
3030
assert(False)
3131

32+
# Benchmark to measure the time it takes to perform the slice.
33+
@pytest.mark.parametrize("dim", [5000, 10000, 20000])
34+
@pytest.mark.parametrize("format", ['csr'])
35+
@pytest.mark.parametrize("config", sizeConfigs[:len(sizeConfigs)-1])
36+
def bench_slice_sparse_window(tacoBench, dim, format, config):
37+
loader = RandomScipySparseTensorLoader(format)
38+
matrix = loader.random((dim, dim), 0.01).astype('float64')
39+
matrix2 = loader.random((dim, dim), 0.01, variant=1).astype('float64')
40+
def bench():
41+
x = sliceTensor(matrix, dim, config)
42+
x2 = sliceTensor(matrix2, dim, config)
43+
return (x, x2)
44+
tacoBench(bench)
45+
46+
# Benchmark to measure the time it takes to perform the addition.
47+
@pytest.mark.parametrize("dim", [5000, 10000, 20000])
48+
@pytest.mark.parametrize("format", ['csr'])
49+
@pytest.mark.parametrize("config", sizeConfigs[:len(sizeConfigs)-1])
50+
def bench_add_sliced_sparse_window(tacoBench, dim, format, config):
51+
loader = RandomScipySparseTensorLoader(format)
52+
matrix = loader.random((dim, dim), 0.01).astype('float64')
53+
matrix2 = loader.random((dim, dim), 0.01, variant=1).astype('float64')
54+
x = sliceTensor(matrix, dim, config)
55+
x2 = sliceTensor(matrix2, dim, config)
56+
def bench():
57+
return x + x2
58+
tacoBench(bench)
59+
60+
# Benchmark that performs the slice and addition.
3261
@pytest.mark.parametrize("dim", [5000, 10000, 20000])
3362
@pytest.mark.parametrize("format", ['csr'])
3463
@pytest.mark.parametrize("config", sizeConfigs)
@@ -44,8 +73,30 @@ def bench():
4473
# res = matrix + matrix
4574
tacoBench(bench)
4675

47-
# TODO (rohany): This is really slow (compared to scipy.sparse). Check with hameer
48-
# that this result makes sense.
76+
@pytest.mark.parametrize("dim", [5000, 10000, 20000])
77+
@pytest.mark.parametrize("config", sizeConfigs[:len(sizeConfigs)-1])
78+
def bench_slice_pydata_sparse_window(tacoBench, dim, config):
79+
loader = RandomPydataSparseTensorLoader()
80+
matrix = loader.random((dim, dim), 0.01).astype('float64')
81+
matrix2 = loader.random((dim, dim), 0.01, variant=1).astype('float64')
82+
def bench():
83+
x = sliceTensor(matrix, dim, config)
84+
x2 = sliceTensor(matrix2, dim, config)
85+
return (x, x2)
86+
tacoBench(bench)
87+
88+
@pytest.mark.parametrize("dim", [5000, 10000, 20000])
89+
@pytest.mark.parametrize("config", sizeConfigs[:len(sizeConfigs)-1])
90+
def bench_add_sliced_pydata_sparse_window(tacoBench, dim, config):
91+
loader = RandomPydataSparseTensorLoader()
92+
matrix = loader.random((dim, dim), 0.01).astype('float64')
93+
matrix2 = loader.random((dim, dim), 0.01, variant=1).astype('float64')
94+
x = sliceTensor(matrix, dim, config)
95+
x2 = sliceTensor(matrix2, dim, config)
96+
def bench():
97+
return x + x2
98+
tacoBench(bench)
99+
49100
@pytest.mark.parametrize("dim", [5000, 10000, 20000])
50101
@pytest.mark.parametrize("config", sizeConfigs)
51102
def bench_add_pydata_sparse_window(tacoBench, dim, config):
@@ -61,56 +112,75 @@ def bench():
61112
@pytest.mark.parametrize("dim", [5000, 10000, 20000])
62113
@pytest.mark.parametrize("format", ['csr'])
63114
@pytest.mark.parametrize("strideWidth", [2, 4, 8])
64-
def bench_add_sparse_strided_window(tacoBench, dim, format, strideWidth):
115+
def bench_slice_strided_window(tacoBench, dim, format, strideWidth):
65116
loader = RandomScipySparseTensorLoader(format)
66117
matrix = loader.random((dim, dim), 0.01).astype('float64')
67118
matrix2 = loader.random((dim, dim), 0.01, variant=1).astype('float64')
68119
def bench():
69120
x = matrix[0:dim:strideWidth, 0:dim:strideWidth]
70121
x2 = matrix2[0:dim:strideWidth, 0:dim:strideWidth]
122+
return (x, x2)
123+
tacoBench(bench)
124+
125+
@pytest.mark.parametrize("dim", [5000, 10000, 20000])
126+
@pytest.mark.parametrize("format", ['csr'])
127+
@pytest.mark.parametrize("strideWidth", [2, 4, 8])
128+
def bench_add_sliced_sparse_strided_window(tacoBench, dim, format, strideWidth):
129+
loader = RandomScipySparseTensorLoader(format)
130+
matrix = loader.random((dim, dim), 0.01).astype('float64')
131+
matrix2 = loader.random((dim, dim), 0.01, variant=1).astype('float64')
132+
x = matrix[0:dim:strideWidth, 0:dim:strideWidth]
133+
x2 = matrix2[0:dim:strideWidth, 0:dim:strideWidth]
134+
def bench():
71135
res = x + x2
72136
tacoBench(bench)
73137

74138
@pytest.mark.parametrize("dim", [5000, 10000, 20000])
75-
@pytest.mark.parametrize("format", ['csr', 'csc'])
76-
@pytest.mark.parametrize("fraction", [2, 4, 8])
77-
@pytest.mark.skip(reason="not doing index sets")
78-
def bench_add_sparse_index_set(tacoBench, dim, format, fraction):
79-
indexes = [i * fraction for i in range(0, dim//fraction)]
139+
@pytest.mark.parametrize("format", ['csr'])
140+
@pytest.mark.parametrize("strideWidth", [2, 4, 8])
141+
def bench_add_sparse_strided_window(tacoBench, dim, format, strideWidth):
80142
loader = RandomScipySparseTensorLoader(format)
81-
matrix = loader.random((dim, dim), 0.01)
82-
matrix2 = loader.random((dim, dim), 0.01, variant=1)
143+
matrix = loader.random((dim, dim), 0.01).astype('float64')
144+
matrix2 = loader.random((dim, dim), 0.01, variant=1).astype('float64')
83145
def bench():
84-
x = matrix[:, indexes]
85-
x2 = matrix2[:, indexes]
146+
x = matrix[0:dim:strideWidth, 0:dim:strideWidth]
147+
x2 = matrix2[0:dim:strideWidth, 0:dim:strideWidth]
86148
res = x + x2
87149
tacoBench(bench)
88150

89151
@pytest.mark.parametrize("dim", [5000, 10000, 20000])
90152
@pytest.mark.parametrize("strideWidth", [2, 4, 8])
91-
def bench_add_pydata_sparse_strided_window(tacoBench, dim, strideWidth):
153+
def bench_slice_pydata_sparse_strided_window(tacoBench, dim, strideWidth):
92154
loader = RandomPydataSparseTensorLoader()
93155
matrix = loader.random((dim, dim), 0.01).astype('float64')
94156
matrix2 = loader.random((dim, dim), 0.01, variant=1).astype('float64')
95157
def bench():
96158
x = matrix[0:dim:strideWidth, 0:dim:strideWidth]
97159
x2 = matrix2[0:dim:strideWidth, 0:dim:strideWidth]
160+
return (x, x2)
161+
tacoBench(bench)
162+
163+
@pytest.mark.parametrize("dim", [5000, 10000, 20000])
164+
@pytest.mark.parametrize("strideWidth", [2, 4, 8])
165+
def bench_add_sliced_pydata_sparse_strided_window(tacoBench, dim, strideWidth):
166+
loader = RandomPydataSparseTensorLoader()
167+
matrix = loader.random((dim, dim), 0.01).astype('float64')
168+
matrix2 = loader.random((dim, dim), 0.01, variant=1).astype('float64')
169+
x = matrix[0:dim:strideWidth, 0:dim:strideWidth]
170+
x2 = matrix2[0:dim:strideWidth, 0:dim:strideWidth]
171+
def bench():
98172
res = x + x2
99173
tacoBench(bench)
100174

101-
# TODO (rohany): This is really slow (compared to scipy.sparse). Check with hameer
102-
# that this result makes sense.
103175
@pytest.mark.parametrize("dim", [5000, 10000, 20000])
104-
@pytest.mark.parametrize("fraction", [2, 4, 8])
105-
@pytest.mark.skip(reason="not doing index sets")
106-
def bench_add_pydata_sparse_index_set(tacoBench, dim, fraction):
176+
@pytest.mark.parametrize("strideWidth", [2, 4, 8])
177+
def bench_add_pydata_sparse_strided_window(tacoBench, dim, strideWidth):
107178
loader = RandomPydataSparseTensorLoader()
108-
indexes = [i * fraction for i in range(0, dim//fraction)]
109-
matrix = loader.random((dim, dim), 0.01)
110-
matrix2 = loader.random((dim, dim), 0.01, variant=1)
179+
matrix = loader.random((dim, dim), 0.01).astype('float64')
180+
matrix2 = loader.random((dim, dim), 0.01, variant=1).astype('float64')
111181
def bench():
112-
x = matrix[:, indexes]
113-
x2 = matrix2[:, indexes]
182+
x = matrix[0:dim:strideWidth, 0:dim:strideWidth]
183+
x2 = matrix2[0:dim:strideWidth, 0:dim:strideWidth]
114184
res = x + x2
115185
tacoBench(bench)
116186

@@ -133,3 +203,34 @@ def bench():
133203
res = x + x
134204
tacoBench(bench)
135205

206+
@pytest.mark.parametrize("dim", [5000, 10000, 20000])
207+
@pytest.mark.parametrize("format", ['csr', 'csc'])
208+
@pytest.mark.parametrize("fraction", [2, 4, 8])
209+
@pytest.mark.skip(reason="not doing index sets")
210+
def bench_add_sparse_index_set(tacoBench, dim, format, fraction):
211+
indexes = [i * fraction for i in range(0, dim//fraction)]
212+
loader = RandomScipySparseTensorLoader(format)
213+
matrix = loader.random((dim, dim), 0.01)
214+
matrix2 = loader.random((dim, dim), 0.01, variant=1)
215+
def bench():
216+
x = matrix[:, indexes]
217+
x2 = matrix2[:, indexes]
218+
res = x + x2
219+
tacoBench(bench)
220+
221+
# TODO (rohany): This is really slow (compared to scipy.sparse). Check with hameer
222+
# that this result makes sense.
223+
@pytest.mark.parametrize("dim", [5000, 10000, 20000])
224+
@pytest.mark.parametrize("fraction", [2, 4, 8])
225+
@pytest.mark.skip(reason="not doing index sets")
226+
def bench_add_pydata_sparse_index_set(tacoBench, dim, fraction):
227+
loader = RandomPydataSparseTensorLoader()
228+
indexes = [i * fraction for i in range(0, dim//fraction)]
229+
matrix = loader.random((dim, dim), 0.01)
230+
matrix2 = loader.random((dim, dim), 0.01, variant=1)
231+
def bench():
232+
x = matrix[:, indexes]
233+
x2 = matrix2[:, indexes]
234+
res = x + x2
235+
tacoBench(bench)
236+

0 commit comments

Comments
 (0)