Skip to content

Commit 928df3e

Browse files
petrmitrichevcopybara-github
authored andcommitted
Add a benchmark for the subslice operation.
PiperOrigin-RevId: 714954429 Change-Id: I322e6b5b38a5629e9f14aeebb3aab2511c5c436b
1 parent 5b29b43 commit 928df3e

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

py/koladata/benchmarks.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,5 +1379,38 @@ def databag_repr_fallbacks(state):
13791379
_ = repr(e.db)
13801380

13811381

1382+
@google_benchmark.register
1383+
@google_benchmark.option.arg_names(['sorted_indices'])
1384+
@google_benchmark.option.args([False])
1385+
@google_benchmark.option.args([True])
1386+
def subslice(state):
1387+
"""Benchmark ds.S."""
1388+
sorted_indices = state.range(0)
1389+
num_dims = 5
1390+
min_size = 10
1391+
max_size = 20
1392+
ds = kd.present
1393+
# Create random ragged data.
1394+
for step in range(num_dims):
1395+
ds = ds.repeat(kd.randint_like(ds, min_size, max_size + 1, seed=step))
1396+
# Replace repeated values with random values.
1397+
ds = kd.randint_like(ds, 1, 100, seed=57)
1398+
# Choose random indices to take.
1399+
indices = []
1400+
chosen = kd.implode(ds, -1)
1401+
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))
1409+
indices.append(take)
1410+
chosen = chosen[take]
1411+
while state:
1412+
_ = ds.S[*indices]
1413+
1414+
13821415
if __name__ == '__main__':
13831416
google_benchmark.main()

0 commit comments

Comments
 (0)