From 6638ea9ca37377a8136fb25f64f7c7710f641cd2 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 7 May 2014 21:33:36 +0300 Subject: [PATCH] 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. --- tests/bench/var-6.1-instance-attr-5.py | 18 ++++++++++++++++++ tests/bench/var-8.1-namedtuple-5th.py | 12 ++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/bench/var-6.1-instance-attr-5.py create mode 100644 tests/bench/var-8.1-namedtuple-5th.py diff --git a/tests/bench/var-6.1-instance-attr-5.py b/tests/bench/var-6.1-instance-attr-5.py new file mode 100644 index 0000000000..e8d3383605 --- /dev/null +++ b/tests/bench/var-6.1-instance-attr-5.py @@ -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) diff --git a/tests/bench/var-8.1-namedtuple-5th.py b/tests/bench/var-8.1-namedtuple-5th.py new file mode 100644 index 0000000000..2cd6d15a0d --- /dev/null +++ b/tests/bench/var-8.1-namedtuple-5th.py @@ -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)