Skip to content

Commit d28844d

Browse files
AJMansfielddpgeorge
authored andcommitted
tests/internal_bench/var: Benchmark checked attribute access.
This commit also includes a fix to the `var-6.2-instance-speciallookup.py` test originally added by 82db5c8 / micropython#16806, as the `__getattr__` method actually does not trigger a class's special lookups flag as originally believed. Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
1 parent 6d09d3e commit d28844d

8 files changed

Lines changed: 138 additions & 1 deletion

tests/internal_bench/var-6.2-instance-speciallookup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Foo:
55
def __init__(self):
66
self.num = 20000000
77

8-
def __getattr__(self, name): # just trigger the 'special lookups' flag on the class
8+
def __delattr__(self, name): # just trigger the 'special lookups' flag on the class
99
pass
1010

1111

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+
pass
6+
7+
8+
def test(num):
9+
o = Foo()
10+
o.num = num
11+
i = 0
12+
while i < getattr(o, "num", num):
13+
i += 1
14+
15+
16+
bench.run(test)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import bench
2+
3+
4+
class Foo:
5+
pass
6+
7+
8+
def test(num):
9+
o = Foo()
10+
i = 0
11+
while i < getattr(o, "num", num):
12+
i += 1
13+
14+
15+
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 __delattr__(self, name): # just trigger the 'special lookups' flag on the class
6+
pass
7+
8+
9+
def test(num):
10+
o = Foo()
11+
i = 0
12+
while i < getattr(o, "num", num):
13+
i += 1
14+
15+
16+
bench.run(test)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import bench
2+
3+
4+
class Foo:
5+
pass
6+
7+
8+
def test(num):
9+
o = Foo()
10+
o.num = num
11+
12+
def get():
13+
try:
14+
return o.num
15+
except AttributeError:
16+
return num
17+
18+
i = 0
19+
while i < get():
20+
i += 1
21+
22+
23+
bench.run(test)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import bench
2+
3+
4+
class Foo:
5+
pass
6+
7+
8+
def test(num):
9+
o = Foo()
10+
11+
def get():
12+
try:
13+
raise AttributeError
14+
except AttributeError:
15+
return num
16+
17+
i = 0
18+
while i < get():
19+
i += 1
20+
21+
22+
bench.run(test)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import bench
2+
3+
4+
class Foo:
5+
pass
6+
7+
8+
def test(num):
9+
o = Foo()
10+
11+
def get():
12+
try:
13+
return o.num
14+
except AttributeError:
15+
return num
16+
17+
i = 0
18+
while i < get():
19+
i += 1
20+
21+
22+
bench.run(test)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import bench
2+
3+
4+
class Foo:
5+
def __delattr__(self, name): # just trigger the 'special lookups' flag on the class
6+
pass
7+
8+
9+
def test(num):
10+
o = Foo()
11+
12+
def get():
13+
try:
14+
return o.num
15+
except AttributeError:
16+
return num
17+
18+
i = 0
19+
while i < get():
20+
i += 1
21+
22+
23+
bench.run(test)

0 commit comments

Comments
 (0)