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:
parent
aaff82afe5
commit
f01fa458d8
11
tests/bench/var-5-class-attr.py
Normal file
11
tests/bench/var-5-class-attr.py
Normal 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)
|
14
tests/bench/var-6-instance-attr.py
Normal file
14
tests/bench/var-6-instance-attr.py
Normal 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)
|
17
tests/bench/var-7-instance-meth.py
Normal file
17
tests/bench/var-7-instance-meth.py
Normal 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)
|
Loading…
x
Reference in New Issue
Block a user