diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-05-05 02:17:13 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-05-05 02:17:13 +0300 |
commit | f01fa458d869d6f89f65ba3ad163730b1e2451d6 (patch) | |
tree | c8a4b9f04e498bdd6547a752dd101c99f1c00dee /tests/bench | |
parent | aaff82afe5a72ec69e05f1e56047d0acfde91d0e (diff) | |
download | micropython-f01fa458d869d6f89f65ba3ad163730b1e2451d6.tar.gz micropython-f01fa458d869d6f89f65ba3ad163730b1e2451d6.zip |
tests/bench/var: Add tests for class/instance var access.
Also compared with method abstraction for accessing instance vars -
it's more than 3 times slower than accessing var directly.
Diffstat (limited to 'tests/bench')
-rw-r--r-- | tests/bench/var-5-class-attr.py | 11 | ||||
-rw-r--r-- | tests/bench/var-6-instance-attr.py | 14 | ||||
-rw-r--r-- | tests/bench/var-7-instance-meth.py | 17 |
3 files changed, 42 insertions, 0 deletions
diff --git a/tests/bench/var-5-class-attr.py b/tests/bench/var-5-class-attr.py new file mode 100644 index 0000000000..02ae874ac2 --- /dev/null +++ b/tests/bench/var-5-class-attr.py @@ -0,0 +1,11 @@ +import bench + +class Foo: + num = 20000000 + +def test(num): + i = 0 + while i < Foo.num: + i += 1 + +bench.run(test) diff --git a/tests/bench/var-6-instance-attr.py b/tests/bench/var-6-instance-attr.py new file mode 100644 index 0000000000..787ed870fb --- /dev/null +++ b/tests/bench/var-6-instance-attr.py @@ -0,0 +1,14 @@ +import bench + +class Foo: + + def __init__(self): + 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-7-instance-meth.py b/tests/bench/var-7-instance-meth.py new file mode 100644 index 0000000000..f9d463f40a --- /dev/null +++ b/tests/bench/var-7-instance-meth.py @@ -0,0 +1,17 @@ +import bench + +class Foo: + + def __init__(self): + self._num = 20000000 + + def num(self): + return self._num + +def test(num): + o = Foo() + i = 0 + while i < o.num(): + i += 1 + +bench.run(test) |