Skip to content

Commit 04d3702

Browse files
committed
tests/internal_bench/var: Benchmark descriptor access.
Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
1 parent 589c488 commit 04d3702

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-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):
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)

0 commit comments

Comments
 (0)