annotate Tools/pybench/With.py @ 65035:87f4b32905df 2.7

Cosmetic fix to use print function.
author Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
date Fri, 01 Oct 2010 10:48:47 +0000
parents 15842094b089
children 63741c7521aa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
45717
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
1 from __future__ import with_statement
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
2 from pybench import Test
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
3
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
4 class WithFinally(Test):
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
5
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
6 version = 2.0
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
7 operations = 20
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
8 rounds = 80000
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
9
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
10 class ContextManager(object):
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
11 def __enter__(self):
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
12 pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
13 def __exit__(self, exc, val, tb):
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
14 pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
15
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
16 def test(self):
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
17
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
18 cm = self.ContextManager()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
19
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
20 for i in xrange(self.rounds):
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
21 with cm: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
22 with cm: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
23 with cm: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
24 with cm: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
25 with cm: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
26 with cm: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
27 with cm: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
28 with cm: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
29 with cm: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
30 with cm: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
31 with cm: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
32 with cm: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
33 with cm: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
34 with cm: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
35 with cm: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
36 with cm: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
37 with cm: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
38 with cm: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
39 with cm: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
40 with cm: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
41
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
42 def calibrate(self):
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
43
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
44 cm = self.ContextManager()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
45
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
46 for i in xrange(self.rounds):
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
47 pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
48
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
49
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
50 class TryFinally(Test):
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
51
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
52 version = 2.0
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
53 operations = 20
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
54 rounds = 80000
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
55
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
56 class ContextManager(object):
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
57 def __enter__(self):
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
58 pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
59 def __exit__(self):
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
60 # "Context manager" objects used just for their cleanup
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
61 # actions in finally blocks usually don't have parameters.
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
62 pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
63
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
64 def test(self):
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
65
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
66 cm = self.ContextManager()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
67
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
68 for i in xrange(self.rounds):
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
69 cm.__enter__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
70 try: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
71 finally: cm.__exit__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
72
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
73 cm.__enter__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
74 try: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
75 finally: cm.__exit__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
76
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
77 cm.__enter__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
78 try: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
79 finally: cm.__exit__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
80
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
81 cm.__enter__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
82 try: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
83 finally: cm.__exit__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
84
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
85 cm.__enter__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
86 try: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
87 finally: cm.__exit__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
88
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
89 cm.__enter__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
90 try: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
91 finally: cm.__exit__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
92
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
93 cm.__enter__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
94 try: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
95 finally: cm.__exit__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
96
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
97 cm.__enter__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
98 try: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
99 finally: cm.__exit__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
100
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
101 cm.__enter__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
102 try: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
103 finally: cm.__exit__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
104
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
105 cm.__enter__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
106 try: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
107 finally: cm.__exit__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
108
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
109 cm.__enter__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
110 try: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
111 finally: cm.__exit__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
112
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
113 cm.__enter__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
114 try: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
115 finally: cm.__exit__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
116
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
117 cm.__enter__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
118 try: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
119 finally: cm.__exit__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
120
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
121 cm.__enter__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
122 try: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
123 finally: cm.__exit__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
124
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
125 cm.__enter__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
126 try: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
127 finally: cm.__exit__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
128
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
129 cm.__enter__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
130 try: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
131 finally: cm.__exit__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
132
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
133 cm.__enter__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
134 try: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
135 finally: cm.__exit__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
136
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
137 cm.__enter__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
138 try: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
139 finally: cm.__exit__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
140
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
141 cm.__enter__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
142 try: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
143 finally: cm.__exit__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
144
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
145 cm.__enter__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
146 try: pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
147 finally: cm.__exit__()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
148
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
149 def calibrate(self):
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
150
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
151 cm = self.ContextManager()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
152
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
153 for i in xrange(self.rounds):
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
154 pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
155
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
156
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
157 class WithRaiseExcept(Test):
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
158
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
159 version = 2.0
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
160 operations = 2 + 3 + 3
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
161 rounds = 100000
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
162
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
163 class BlockExceptions(object):
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
164 def __enter__(self):
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
165 pass
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
166 def __exit__(self, exc, val, tb):
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
167 return True
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
168
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
169 def test(self):
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
170
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
171 error = ValueError
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
172 be = self.BlockExceptions()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
173
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
174 for i in xrange(self.rounds):
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
175 with be: raise error
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
176 with be: raise error
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
177 with be: raise error,"something"
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
178 with be: raise error,"something"
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
179 with be: raise error,"something"
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
180 with be: raise error("something")
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
181 with be: raise error("something")
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
182 with be: raise error("something")
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
183
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
184 def calibrate(self):
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
185
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
186 error = ValueError
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
187 be = self.BlockExceptions()
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
188
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
189 for i in xrange(self.rounds):
15842094b089 Add tests for with and finally performance to pybench.
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
diff changeset
190 pass