-
-
Save colesbury/7d43e7dde89c1cb5574b5a2c73cc52b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Create a bunch of different classes so that attribute accesses are | |
| # polymorphic (i.e., the inline caches can't specialize for a single type). | |
| _type_lookup_classes = [] | |
| _type_lookup_attrs = {f"attr_{_i}": _i for _i in range(20)} | |
| for _i in range(20): | |
| _cls = type(f"C{_i}", (_TypeLookupBase,), _type_lookup_attrs) | |
| _type_lookup_classes.append(_cls) | |
| @register_benchmark | |
| def type_attr_lookup(): | |
| objects = [cls() for cls in _type_lookup_classes] | |
| for i in range(50 * WORK_SCALE): | |
| for obj in objects: | |
| obj.attr_0 | |
| obj.attr_1 | |
| obj.attr_2 | |
| obj.attr_3 | |
| obj.attr_4 | |
| obj.attr_5 | |
| obj.attr_6 | |
| obj.attr_7 | |
| obj.attr_8 | |
| obj.attr_9 | |
| obj.attr_10 | |
| obj.attr_11 | |
| obj.attr_12 | |
| obj.attr_13 | |
| obj.attr_14 | |
| obj.attr_15 | |
| obj.attr_16 | |
| obj.attr_17 | |
| obj.attr_18 | |
| obj.attr_19 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment