tests/internal_bench/var: Benchmark descriptor access.

Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
This commit is contained in:
Anson Mansfield
2025-07-20 12:07:05 -04:00
committed by Damien George
parent c3e77ad6db
commit b9d6d6af4b
4 changed files with 72 additions and 0 deletions

View 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)

View 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)

View 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)

View 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)