Skip to content

Commit 2409a66

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

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy