Skip to content

Commit 6638ea9

Browse files
committed
tests/bench: Add testcases for lookup in 5-el instance and namedtuple.
... and we have not that bad mapping type after all - lookup time is ~ the same as in one-attr instance. My namedtuple implementation on the other hand degrades awfully. So, need to rework it. First observation is that named tuple fields are accessed as attributes, so all names are interned at the program start. Then, really should store field array as qstr[], and do quick 32/64 bit scan thru it.
1 parent 52b2529 commit 6638ea9

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import bench
2+
3+
class Foo:
4+
5+
def __init__(self):
6+
self.num1 = 0
7+
self.num2 = 0
8+
self.num3 = 0
9+
self.num4 = 0
10+
self.num = 20000000
11+
12+
def test(num):
13+
o = Foo()
14+
i = 0
15+
while i < o.num:
16+
i += 1
17+
18+
bench.run(test)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import bench
2+
from _collections import namedtuple
3+
4+
T = namedtuple("Tup", "foo1 foo2 foo3 foo4 num")
5+
6+
def test(num):
7+
t = T(0, 0, 0, 0, 20000000)
8+
i = 0
9+
while i < t.num:
10+
i += 1
11+
12+
bench.run(test)

0 commit comments

Comments
 (0)