Created
August 23, 2020 17:24
-
-
Save Infernio/f3a2cb592afe805c5ff691f79f8e8e5d 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
PS C:\Users\Infernio> py -2 -m timeit -s """ | |
>> class Foo(object): | |
>> bar = 'test' | |
>> | |
>> o = Foo() | |
>> getter = o.__getattribute__ | |
>> """ "getter('bar')" | |
10000000 loops, best of 3: 0.044 usec per loop | |
PS C:\Users\Infernio> py -2 -m timeit -s """ | |
>> class Foo(object): | |
>> bar = 'test' | |
>> | |
>> o = Foo() | |
>> getter = o.__getattribute__ | |
>> """ "getattr(o, 'bar')" | |
10000000 loops, best of 3: 0.0533 usec per loop | |
PS C:\Users\Infernio> py -2 -m timeit -s """ | |
>> class Foo(object): | |
>> bar = 'test' | |
>> | |
>> o = Foo() | |
>> getter = o.__getattribute__ | |
>> """ "o.__getattribute__('bar')" | |
10000000 loops, best of 3: 0.0741 usec per loop | |
PS C:\Users\Infernio> py -3 -m timeit -s """ | |
>> class Foo(object): | |
>> bar = 'test' | |
>> | |
>> o = Foo() | |
>> getter = o.__getattribute__ | |
>> """ "getter('bar')" | |
10000000 loops, best of 5: 37 nsec per loop | |
PS C:\Users\Infernio> py -3 -m timeit -s """ | |
>> class Foo(object): | |
>> bar = 'test' | |
>> | |
>> o = Foo() | |
>> getter = o.__getattribute__ | |
>> """ "getattr(o, 'bar')" | |
10000000 loops, best of 5: 31.6 nsec per loop | |
PS C:\Users\Infernio> py -3 -m timeit -s """ | |
>> class Foo(object): | |
>> bar = 'test' | |
>> | |
>> o = Foo() | |
>> getter = o.__getattribute__ | |
>> """ "o.__getattribute__('bar')" | |
5000000 loops, best of 5: 58.6 nsec per loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment