Skip to content

Commit ef593bb

Browse files
committed
refinements to performance charts
1 parent 7e24be9 commit ef593bb

File tree

1 file changed

+38
-15
lines changed

1 file changed

+38
-15
lines changed

doc/articles/block_index.py

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def __init__(self, arrays: tp.Iterable[np.ndarray]):
7676
self.selector_int_array = np.arange(0, len(self.bi), 2)
7777
self.selector_int_list = list(range(0, len(self.bi), 2))
7878
self.selector_bool_array = (np.arange(len(self.bi)) % 2) == 0
79+
self.selector_slice = slice(0, len(self.bi), 2)
7980

8081
#-------------------------------------------------------------------------------
8182
class BlockIndexLoad(ArrayProcessor):
@@ -191,17 +192,34 @@ def __call__(self):
191192
_ = [ti[i] for i in self.selector_int_list]
192193

193194

195+
class BlockIndexIterSlice(ArrayProcessor):
196+
NAME = 'BlockIndex: iter by slice'
197+
SORT = 7
198+
199+
def __call__(self):
200+
_ = list(self.bi.iter_select(self.selector_slice))
201+
202+
class TupleIndexIterSlice(ArrayProcessor):
203+
NAME = 'TupleIndex: iter by slice'
204+
SORT = 17
205+
206+
def __call__(self):
207+
ti = self.ti
208+
_ = list(iter(ti[self.selector_slice]))
209+
210+
211+
194212

195213
class BlockIndexIterBoolArray(ArrayProcessor):
196214
NAME = 'BlockIndex: iter by bool array'
197-
SORT = 7
215+
SORT = 8
198216

199217
def __call__(self):
200218
_ = list(self.bi.iter_select(self.selector_bool_array))
201219

202220
class TupleIndexIterBoolArray(ArrayProcessor):
203221
NAME = 'TupleIndex: iter by bool array'
204-
SORT = 17
222+
SORT = 18
205223

206224
def __call__(self):
207225
ti = self.ti
@@ -244,14 +262,16 @@ def plot_performance(frame):
244262
fixture = fixture.sort_values('sort')
245263

246264
results = fixture['time'].values.tolist()
247-
names = [cls.NAME for cls in fixture['cls_processor']]
248-
# x = np.arange(len(results))
249-
names_display = names
250-
post = ax.bar(names_display, results, color=color)
265+
x_labels = [f'{i}: {cls.NAME}' for i, cls in
266+
zip(range(1, len(results) + 1), fixture['cls_processor'])
267+
]
268+
x_tick_labels = [str(l + 1) for l in range(len(x_labels))]
269+
x = np.arange(len(results))
270+
x_bar = ax.bar(x_labels, results, color=color)
251271

252272
title = f'{cat_label:.0e}\n{fixture_label}'
253273
ax.set_title(title, fontsize=6)
254-
ax.set_box_aspect(0.75) # makes taller tan wide
274+
ax.set_box_aspect(0.5) # larger makes taller tan wide
255275

256276
time_max = fixture["time"].max()
257277
time_min = fixture["time"].min()
@@ -269,22 +289,24 @@ def plot_performance(frame):
269289

270290
ax.set_yticks(y_ticks)
271291
ax.set_yticklabels(y_labels, fontsize=4)
272-
# ax.set_xticks(x, names_display, rotation='vertical')
273292
ax.tick_params(
274-
axis="x",
275-
bottom=False,
276-
labelbottom=False,
293+
axis="y",
294+
length=2,
295+
width=0.5,
296+
pad=1,
277297
)
298+
ax.set_xticks(x)
299+
ax.set_xticklabels(x_tick_labels, fontsize=4)
278300
ax.tick_params(
279-
axis="y",
301+
axis="x",
280302
length=2,
281303
width=0.5,
282304
pad=1,
283305
)
284306
# ax.set_yscale('log')
285307

286308
fig.set_size_inches(9, 3.5) # width, height
287-
fig.legend(post, names_display, loc='center right', fontsize=6)
309+
fig.legend(x_bar, x_labels, loc='center right', fontsize=6)
288310
# horizontal, vertical
289311
fig.text(.05, .96, f'BlockIndex Performance: {NUMBER} Iterations', fontsize=10)
290312
fig.text(.05, .90, get_versions(), fontsize=6)
@@ -295,7 +317,7 @@ def plot_performance(frame):
295317
bottom=0.05,
296318
right=0.80,
297319
top=0.80,
298-
wspace=1, # width
320+
wspace=0.6, # width
299321
hspace=0.6,
300322
)
301323
# plt.rcParams.update({'font.size': 22})
@@ -380,7 +402,8 @@ def get_versions() -> str:
380402
TupleIndexIterIntList,
381403
BlockIndexIterBoolArray,
382404
TupleIndexIterBoolArray,
383-
405+
BlockIndexIterSlice,
406+
TupleIndexIterSlice,
384407
)
385408

386409
CLS_FF = (

0 commit comments

Comments
 (0)