Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Bobronium/504ebdc5d2b727d85be05f6dffd577c7 to your computer and use it in GitHub Desktop.
Save Bobronium/504ebdc5d2b727d85be05f6dffd577c7 to your computer and use it in GitHub Desktop.
ATTR_ACCESS:
Testing with 1000000 repeats:
>>> Qrator.FOO # 0.04096488799999998 seconds
<Qrator.FOO: FOO>
>>> BuiltinPatched.FOO # 0.038564896999999654 seconds
<BuiltinPatched.FOO: 'FOO'>
>>> Qrator.FOO.value # 0.058468369999999936 seconds
'FOO'
>>> BuiltinPatched.FOO.value # 0.056412388000000036 seconds
'FOO'
Fastest BuiltinPatched: 0.09497728499999969 seconds in total, 0.04664266215326929 average
Slowest Qrator: 0.09943325799999991 seconds in total, 0.04894027205270272 average
BuiltinPatched faster by: x1.0492598362392656 times (in average)
INHERITANCE:
Testing with 1000000 repeats:
>>> issubclass(Qrator, Enum) # 0.1498322510000003 seconds
False
>>> issubclass(BuiltinPatched, Enum) # 0.15023139899999993 seconds
True
>>> isinstance(Qrator.FOO, Enum) # 0.20807850799999983 seconds
False
>>> isinstance(BuiltinPatched.FOO, Enum) # 0.1691667300000006 seconds
True
>>> isinstance(Qrator.FOO, Qrator) # 0.09735399999999927 seconds
True
>>> isinstance(BuiltinPatched.FOO, BuiltinPatched) # 0.09426187800000108 seconds
True
>>> isinstance(Qrator.FOO, str) # 0.14657675099999956 seconds
False
>>> isinstance(BuiltinPatched.FOO, str) # 0.12612273300000076 seconds
True
Fastest BuiltinPatched: 0.5397827400000024 seconds in total, 0.13184124083774165 average
Slowest Qrator: 0.601841509999999 seconds in total, 0.14523217957964385 average
BuiltinPatched faster by: x1.1015686643785654 times (in average)
TRYING_VALUES:
Testing with 1000000 repeats:
>>> try: Qrator.FOO = 'new' except: pass # 0.7232219640000004 seconds
TypeError('Enum-like classes strictly prohibit changing any attribute/property after they are once set')
>>> try: BuiltinPatched.FOO = 'new' except: pass # 0.8591889689999981 seconds
AttributeError('Cannot reassign members.')
>>> try: Qrator('unknown') except: pass # 0.783849945 seconds
ValueError('Value unknown is not found in this enum type declaration')
>>> try: BuiltinPatched('unknown') except: pass # 1.7302676559999988 seconds
ValueError("'unknown' is not a valid BuiltinPatched")
>>> Qrator('FOO') # 0.3732641100000009 seconds
<Qrator.FOO: FOO>
>>> BuiltinPatched('FOO') # 0.42131682600000175 seconds
<BuiltinPatched.FOO: 'FOO'>
>>> try: Qrator(Qrator.FOO) except: pass # 1.8219497480000015 seconds
ValueError('Value Qrator.FOO is not found in this enum type declaration')
>>> BuiltinPatched(BuiltinPatched.FOO) # 0.5067747400000009 seconds
<BuiltinPatched.FOO: 'FOO'>
>>> Qrator['FOO'] # 0.17855032699999995 seconds
<Qrator.FOO: FOO>
>>> BuiltinPatched['FOO'] # 0.16489227500000325 seconds
<BuiltinPatched.FOO: 'FOO'>
Fastest BuiltinPatched: 3.6824404660000027 seconds in total, 0.5543259514100637 average
Slowest Qrator: 3.880836094000003 seconds in total, 0.5855494312090324 average
BuiltinPatched faster by: x1.0563269313290207 times (in average)
MISC:
Testing with 1000000 repeats:
>>> sys.getsizeof(Qrator) # 0.2680310719999994 seconds
896
>>> sys.getsizeof(BuiltinPatched) # 0.273315255 seconds
1064
>>> sys.getsizeof(Qrator.FOO) # 0.2471237319999986 seconds
56
>>> sys.getsizeof(BuiltinPatched.FOO) # 0.24918581499999704 seconds
100
>>> for member in Qrator: pass # 0.3066330480000019 seconds
>>> for member in BuiltinPatched: pass # 0.3112115649999936 seconds
>>> dir(Qrator) # 6.465873008999999 seconds
['BAR', 'FOO', '__annotations__', '__call__', '__class__', '__copy__', '__deepcopy__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__slots__', '__str__', '__subclasshook__', '_finalized', '_value_to_instance_map', 'name', 'value']
>>> dir(BuiltinPatched) # 0.533488650999999 seconds
['BAR', 'FOO', '__class__', '__doc__', '__members__', '__module__']
>>> repr(Qrator) # 0.29007692199999724 seconds
"<class '__main__.Qrator'>"
>>> repr(BuiltinPatched) # 0.47539125899999846 seconds
"<enum 'BuiltinPatched'>"
Fastest BuiltinPatched: 1.842592544999988 seconds in total, 0.3516283304941787 average
Slowest Qrator: 7.577737782999996 seconds in total, 0.5202017169889248 average
BuiltinPatched faster by: x1.4794078630064675 times (in average)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment