Skip to content

Commit 36386ef

Browse files
petrmitrichevcopybara-github
authored andcommitted
Add a benchmark for subslice that uses slices instead of indices.
PiperOrigin-RevId: 715291821 Change-Id: Iaf9c0ae59888821e3c217658472923b4bb93b84b
1 parent f48a994 commit 36386ef

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

py/koladata/benchmarks.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,12 +1380,14 @@ def databag_repr_fallbacks(state):
13801380

13811381

13821382
@google_benchmark.register
1383-
@google_benchmark.option.arg_names(['sorted_indices'])
1384-
@google_benchmark.option.args([False])
1385-
@google_benchmark.option.args([True])
1383+
@google_benchmark.option.arg_names(['sorted_indices', 'use_slices'])
1384+
@google_benchmark.option.args([True, False])
1385+
@google_benchmark.option.args([False, False])
1386+
@google_benchmark.option.args([True, True])
13861387
def subslice(state):
13871388
"""Benchmark ds.S."""
13881389
sorted_indices = state.range(0)
1390+
use_slices = state.range(1)
13891391
num_dims = 5
13901392
min_size = 10
13911393
max_size = 20
@@ -1399,13 +1401,16 @@ def subslice(state):
13991401
indices = []
14001402
chosen = kd.implode(ds, -1)
14011403
for step in range(num_dims):
1402-
available = kd.range(kd.list_size(chosen))
1403-
take = kd.select(
1404-
available, kd.randint_like(available, 0, 2, seed=100 + step) == 0
1405-
)
1406-
if not sorted_indices:
1407-
# Shuffle.
1408-
take = kd.sort(take, kd.randint_like(take, 1, 1000, seed=200 + step))
1404+
if use_slices:
1405+
take = slice(1, -1)
1406+
else:
1407+
available = kd.range(kd.list_size(chosen))
1408+
take = kd.select(
1409+
available, kd.randint_like(available, 0, 2, seed=100 + step) == 0
1410+
)
1411+
if not sorted_indices:
1412+
# Shuffle.
1413+
take = kd.sort(take, kd.randint_like(take, 1, 1000, seed=200 + step))
14091414
indices.append(take)
14101415
chosen = chosen[take]
14111416
while state:

0 commit comments

Comments
 (0)