1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
__author__ = 'Calvin'
import weakref # !
from pyperform import ComparisonBenchmark
class A(object): # !
def __init__(self):
self.count = 0
a = A() # !
ar = weakref.ref(a) # !
@ComparisonBenchmark('Group1', largs=())
def without_weakref():
a = A()
for i in range(1000):
a.count += 1
return a.count
@ComparisonBenchmark('Group1', largs=())
def with_weakref():
for i in range(1000):
ar().count += 1
return ar().count
ComparisonBenchmark.summarize('Group1')
|