tests/internal_bench/var: Benchmark descriptor access.
Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
This commit is contained in:
committed by
Damien George
parent
c3e77ad6db
commit
b9d6d6af4b
19
tests/internal_bench/var-6.2-instance-speciallookup.py
Normal file
19
tests/internal_bench/var-6.2-instance-speciallookup.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import bench
|
||||
|
||||
|
||||
class Foo:
|
||||
def __init__(self):
|
||||
self.num = 20000000
|
||||
|
||||
def __getattr__(self, name): # just trigger the 'special lookups' flag on the class
|
||||
pass
|
||||
|
||||
|
||||
def test(num):
|
||||
o = Foo()
|
||||
i = 0
|
||||
while i < o.num:
|
||||
i += 1
|
||||
|
||||
|
||||
bench.run(test)
|
||||
17
tests/internal_bench/var-6.3-instance-property.py
Normal file
17
tests/internal_bench/var-6.3-instance-property.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import bench
|
||||
|
||||
|
||||
class Foo:
|
||||
@property
|
||||
def num(self):
|
||||
return 20000000
|
||||
|
||||
|
||||
def test(num):
|
||||
o = Foo()
|
||||
i = 0
|
||||
while i < o.num:
|
||||
i += 1
|
||||
|
||||
|
||||
bench.run(test)
|
||||
20
tests/internal_bench/var-6.4-instance-descriptor.py
Normal file
20
tests/internal_bench/var-6.4-instance-descriptor.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import bench
|
||||
|
||||
|
||||
class Descriptor:
|
||||
def __get__(self, instance, owner=None):
|
||||
return 20000000
|
||||
|
||||
|
||||
class Foo:
|
||||
num = Descriptor()
|
||||
|
||||
|
||||
def test(num):
|
||||
o = Foo()
|
||||
i = 0
|
||||
while i < o.num:
|
||||
i += 1
|
||||
|
||||
|
||||
bench.run(test)
|
||||
16
tests/internal_bench/var-6.5-instance-getattr.py
Normal file
16
tests/internal_bench/var-6.5-instance-getattr.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import bench
|
||||
|
||||
|
||||
class Foo:
|
||||
def __getattr__(self, name):
|
||||
return 20000000
|
||||
|
||||
|
||||
def test(num):
|
||||
o = Foo()
|
||||
i = 0
|
||||
while i < o.num:
|
||||
i += 1
|
||||
|
||||
|
||||
bench.run(test)
|
||||
Reference in New Issue
Block a user