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.
This commit is contained in:
Paul Sokolovsky 2014-05-05 02:17:13 +03:00
parent aaff82afe5
commit f01fa458d8
3 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,11 @@
import bench
class Foo:
num = 20000000
def test(num):
i = 0
while i < Foo.num:
i += 1
bench.run(test)

View File

@ -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)

View File

@ -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)