Skip to content

Commit 09ea4d8

Browse files
committed
updated performance tests
1 parent 83ecf71 commit 09ea4d8

File tree

2 files changed

+57
-15
lines changed

2 files changed

+57
-15
lines changed

doc/articles/array2d_to_1d.py renamed to doc/articles/array_to_tuple_array.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,16 @@ class PyArray2D1D(ArrayProcessor):
3333

3434
def __call__(self):
3535
post = np.empty(self.array.shape[0], dtype=object)
36-
for i, row in enumerate(self.array):
37-
post[i] = tuple(row)
36+
if self.array.ndim == 1:
37+
for i, e in enumerate(self.array):
38+
post[i] = (e,)
39+
else:
40+
for i, row in enumerate(self.array):
41+
post[i] = tuple(row)
3842
post.flags.writeable = False
3943

4044
#-------------------------------------------------------------------------------
41-
NUMBER = 200
45+
NUMBER = 1
4246

4347
def seconds_to_display(seconds: float) -> str:
4448
seconds /= NUMBER
@@ -111,7 +115,7 @@ def plot_performance(frame):
111115
bottom=0.05,
112116
right=0.8,
113117
top=0.85,
114-
wspace=0.9, # width
118+
wspace=1.0, # width
115119
hspace=0.5,
116120
)
117121
# plt.rcParams.update({'font.size': 22})
@@ -130,14 +134,17 @@ class FixtureFactory:
130134

131135
@staticmethod
132136
def get_array(size: int, width_ratio: int) -> np.ndarray:
133-
return np.arange(size).reshape(size // width_ratio, width_ratio)
137+
if width_ratio > 1:
138+
return np.arange(size).reshape(size // width_ratio, width_ratio)
139+
return np.arange(size) # return 1D array
134140

135141
@classmethod
136142
def get_label_array(cls, size: int) -> tp.Tuple[str, np.ndarray]:
137143
array = cls.get_array(size)
138144
return cls.NAME, array
139145

140146
DENSITY_TO_DISPLAY = {
147+
'column-1': '1 Column',
141148
'column-2': '2 Column',
142149
'column-5': '5 Column',
143150
'column-10': '10 Column',
@@ -150,6 +157,15 @@ def get_label_array(cls, size: int) -> tp.Tuple[str, np.ndarray]:
150157
# }
151158

152159

160+
class FFC1(FixtureFactory):
161+
NAME = 'column-1'
162+
163+
@staticmethod
164+
def get_array(size: int) -> np.ndarray:
165+
a = FixtureFactory.get_array(size, 1)
166+
return a
167+
168+
153169
class FFC2(FixtureFactory):
154170
NAME = 'column-2'
155171

@@ -193,6 +209,7 @@ def get_versions() -> str:
193209
)
194210

195211
CLS_FF = (
212+
FFC1,
196213
FFC2,
197214
FFC5,
198215
FFC10,

doc/articles/array2d_tuple_iter.py renamed to doc/articles/array_to_tuple_iter.py

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,38 @@ class PyArray2DTupleMapList(ArrayProcessor):
4545

4646
def __call__(self):
4747
array = self.array
48-
_ = list(map(tuple, array))
48+
if array.ndim == 2:
49+
_ = list(map(tuple, array))
50+
else:
51+
_ = list(map(lambda e: (e,), array))
4952

5053
class PyArray2DTupleIterNext(ArrayProcessor):
5154
NAME = 'tuple(next(iter(a2d)))'
5255
SORT = 3
5356

5457
def __call__(self):
55-
it = iter(self.array)
56-
while True:
57-
try:
58-
_ = tuple(next(it))
59-
except StopIteration:
60-
break
58+
array = self.array
59+
it = iter(array)
60+
if array.ndim == 2:
61+
while True:
62+
try:
63+
_ = tuple(next(it))
64+
except StopIteration:
65+
break
66+
else:
67+
while True:
68+
try:
69+
_ = (next(it),)
70+
except StopIteration:
71+
break
72+
6173

6274

6375

6476

6577

6678
#-------------------------------------------------------------------------------
67-
NUMBER = 200
79+
NUMBER = 100
6880

6981
def seconds_to_display(seconds: float) -> str:
7082
seconds /= NUMBER
@@ -156,21 +168,33 @@ class FixtureFactory:
156168

157169
@staticmethod
158170
def get_array(size: int, width_ratio: int) -> np.ndarray:
159-
return np.arange(size).reshape(size // width_ratio, width_ratio)
171+
if width_ratio > 1:
172+
return np.arange(size).reshape(size // width_ratio, width_ratio)
173+
return np.arange(size) # return 1D array
160174

161175
@classmethod
162176
def get_label_array(cls, size: int) -> tp.Tuple[str, np.ndarray]:
163177
array = cls.get_array(size)
164178
return cls.NAME, array
165179

166180
DENSITY_TO_DISPLAY = {
181+
'column-1': '1 Column',
167182
'column-2': '2 Column',
168183
'column-5': '5 Column',
169184
'column-10': '10 Column',
170185
'column-20': '20 Column',
171186
}
172187

173188

189+
class FFC1(FixtureFactory):
190+
NAME = 'column-1'
191+
192+
@staticmethod
193+
def get_array(size: int) -> np.ndarray:
194+
a = FixtureFactory.get_array(size, 1)
195+
return a
196+
197+
174198
class FFC2(FixtureFactory):
175199
NAME = 'column-2'
176200

@@ -217,6 +241,7 @@ def get_versions() -> str:
217241

218242

219243
CLS_FF = (
244+
FFC1,
220245
FFC2,
221246
FFC5,
222247
FFC10,
@@ -226,7 +251,7 @@ def get_versions() -> str:
226251

227252
def run_test():
228253
records = []
229-
for size in (1_000, 10_000, 100_000, 1_000_000):
254+
for size in (1_000, 10_000, 100_000): #, 1_000_000):
230255
for ff in CLS_FF:
231256
fixture_label, fixture = ff.get_label_array(size)
232257
for cls in CLS_PROCESSOR:

0 commit comments

Comments
 (0)