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.
This commit is contained in:
parent
52b25293e2
commit
6638ea9ca3
|
@ -0,0 +1,18 @@
|
||||||
|
import bench
|
||||||
|
|
||||||
|
class Foo:
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.num1 = 0
|
||||||
|
self.num2 = 0
|
||||||
|
self.num3 = 0
|
||||||
|
self.num4 = 0
|
||||||
|
self.num = 20000000
|
||||||
|
|
||||||
|
def test(num):
|
||||||
|
o = Foo()
|
||||||
|
i = 0
|
||||||
|
while i < o.num:
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
bench.run(test)
|
|
@ -0,0 +1,12 @@
|
||||||
|
import bench
|
||||||
|
from _collections import namedtuple
|
||||||
|
|
||||||
|
T = namedtuple("Tup", "foo1 foo2 foo3 foo4 num")
|
||||||
|
|
||||||
|
def test(num):
|
||||||
|
t = T(0, 0, 0, 0, 20000000)
|
||||||
|
i = 0
|
||||||
|
while i < t.num:
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
bench.run(test)
|
Loading…
Reference in New Issue