| import torch.utils.benchmark as benchmark |
| def create_nested_dict_type(layers): |
| return torch._C.StringType.get() |
| less_nested = create_nested_dict_type(layers - 1) |
| result = torch._C.DictType( |
| torch._C.StringType.get(), torch._C.TupleType([less_nested, less_nested]) |
| nesting_levels = (1, 3, 5, 10) |
| types = (reasonable, medium, big, huge) = [ |
| create_nested_dict_type(x) for x in nesting_levels |
| benchmark.Timer(stmt="x.annotation_str", globals={"x": nested_type}) |
| for nesting_level, typ, timer in zip(nesting_levels, types, timers): |
| print("Nesting level:", nesting_level) |
| print("output:", typ.annotation_str[:70]) |
| print(timer.blocked_autorange()) |