Skip to content

Commit e849b56

Browse files
goldvitalycopybara-github
authored andcommitted
Add get_from_dict benchmark.
There seems no such existing benchmark. ``` name cpu/op get_from_dict/size:1/fallback_count:0 1.33µs ± 2% get_from_dict/size:8/fallback_count:0 1.50µs ± 3% get_from_dict/size:64/fallback_count:0 2.51µs ± 3% get_from_dict/size:512/fallback_count:0 10.3µs ± 3% get_from_dict/size:4096/fallback_count:0 73.5µs ± 3% get_from_dict/size:10000/fallback_count:0 181µs ± 3% get_from_dict/size:1/fallback_count:1 2.00µs ± 3% get_from_dict/size:8/fallback_count:1 2.52µs ± 3% get_from_dict/size:64/fallback_count:1 5.93µs ± 2% get_from_dict/size:512/fallback_count:1 33.1µs ± 3% get_from_dict/size:4096/fallback_count:1 251µs ± 3% get_from_dict/size:10000/fallback_count:1 625µs ± 3% get_from_dict/size:1/fallback_count:8 5.40µs ± 2% get_from_dict/size:8/fallback_count:8 10.7µs ± 2% get_from_dict/size:64/fallback_count:8 29.2µs ± 1% get_from_dict/size:512/fallback_count:8 175µs ± 1% get_from_dict/size:4096/fallback_count:8 1.35ms ± 3% get_from_dict/size:10000/fallback_count:8 3.29ms ± 2% get_from_dict/size:1/fallback_count:16 9.23µs ± 2% get_from_dict/size:8/fallback_count:16 16.6µs ± 2% get_from_dict/size:64/fallback_count:16 54.8µs ± 2% get_from_dict/size:512/fallback_count:16 331µs ± 1% get_from_dict/size:4096/fallback_count:16 2.54ms ± 2% get_from_dict/size:10000/fallback_count:16 6.13ms ± 1% ``` PiperOrigin-RevId: 721731207 Change-Id: Iaf90b3d7ef549605559b3a205af7b3801cc22e35
1 parent 61e9ad3 commit e849b56

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

py/koladata/benchmarks.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,25 @@ def set_get_multiple_attrs_10000_entity_via_fallback(state):
13221322
_ = getattr(merged_ds, arg_name)
13231323

13241324

1325+
@google_benchmark.register
1326+
@google_benchmark.option.arg_names(['size', 'fallback_count'])
1327+
@google_benchmark.option.ranges([(1, 10000), (0, 16)])
1328+
def get_from_dict(state):
1329+
"""Benchmark for setting and getting dict key with fallback."""
1330+
size = state.range(0)
1331+
fallback_count = state.range(1)
1332+
ds = kd.dict_shaped(kd.shapes.new([size]))
1333+
for fb_id in range(fallback_count):
1334+
ds = ds.with_dict_update(
1335+
kd.slice([
1336+
'abc' if i % fallback_count == fb_id else None for i in range(size)
1337+
]),
1338+
kd.slice([fb_id] * size),
1339+
)
1340+
while state:
1341+
_ = ds['abc']
1342+
1343+
13251344
@google_benchmark.register
13261345
@google_benchmark.option.arg_names(['nvars'])
13271346
@google_benchmark.option.args([1])

0 commit comments

Comments
 (0)