Skip to content

Commit b9d6d6a

Browse files
AJMansfielddpgeorge
authored andcommitted
tests/internal_bench/var: Benchmark descriptor access.
Signed-off-by: Anson Mansfield <[email protected]>
1 parent c3e77ad commit b9d6d6a

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import bench
2+
3+
4+
class Foo:
5+
def __init__(self):
6+
self.num = 20000000
7+
8+
def __getattr__(self, name): # just trigger the 'special lookups' flag on the class
9+
pass
10+
11+
12+
def test(num):
13+
o = Foo()
14+
i = 0
15+
while i < o.num:
16+
i += 1
17+
18+
19+
bench.run(test)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import bench
2+
3+
4+
class Foo:
5+
@property
6+
def num(self):
7+
return 20000000
8+
9+
10+
def test(num):
11+
o = Foo()
12+
i = 0
13+
while i < o.num:
14+
i += 1
15+
16+
17+
bench.run(test)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import bench
2+
3+
4+
class Descriptor:
5+
def __get__(self, instance, owner=None):
6+
return 20000000
7+
8+
9+
class Foo:
10+
num = Descriptor()
11+
12+
13+
def test(num):
14+
o = Foo()
15+
i = 0
16+
while i < o.num:
17+
i += 1
18+
19+
20+
bench.run(test)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import bench
2+
3+
4+
class Foo:
5+
def __getattr__(self, name):
6+
return 20000000
7+
8+
9+
def test(num):
10+
o = Foo()
11+
i = 0
12+
while i < o.num:
13+
i += 1
14+
15+
16+
bench.run(test)

0 commit comments

Comments
 (0)