File: benchmark_weakref.py

package info (click to toggle)
python-pyperform 1.86-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 168 kB
  • sloc: python: 729; makefile: 17
file content (31 lines) | stat: -rw-r--r-- 517 bytes parent folder | download
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')