1 from __future__
import with_statement
2 from pybench
import Test
4 class WithFinally(Test
):
10 class ContextManager(object):
13 def __exit__(self
, exc
, val
, tb
):
18 cm
= self
.ContextManager()
20 for i
in xrange(self
.rounds
):
44 cm
= self
.ContextManager()
46 for i
in xrange(self
.rounds
):
50 class TryFinally(Test
):
56 class ContextManager(object):
60 # "Context manager" objects used just for their cleanup
61 # actions in finally blocks usually don't have parameters.
66 cm
= self
.ContextManager()
68 for i
in xrange(self
.rounds
):
71 finally: cm
.__exit
__()
75 finally: cm
.__exit
__()
79 finally: cm
.__exit
__()
83 finally: cm
.__exit
__()
87 finally: cm
.__exit
__()
91 finally: cm
.__exit
__()
95 finally: cm
.__exit
__()
99 finally: cm
.__exit
__()
103 finally: cm
.__exit
__()
107 finally: cm
.__exit
__()
111 finally: cm
.__exit
__()
115 finally: cm
.__exit
__()
119 finally: cm
.__exit
__()
123 finally: cm
.__exit
__()
127 finally: cm
.__exit
__()
131 finally: cm
.__exit
__()
135 finally: cm
.__exit
__()
139 finally: cm
.__exit
__()
143 finally: cm
.__exit
__()
147 finally: cm
.__exit
__()
151 cm
= self
.ContextManager()
153 for i
in xrange(self
.rounds
):
157 class WithRaiseExcept(Test
):
160 operations
= 2 + 3 + 3
163 class BlockExceptions(object):
166 def __exit__(self
, exc
, val
, tb
):
172 be
= self
.BlockExceptions()
174 for i
in xrange(self
.rounds
):
177 with be
: raise error
,"something"
178 with be
: raise error
,"something"
179 with be
: raise error
,"something"
180 with be
: raise error("something")
181 with be
: raise error("something")
182 with be
: raise error("something")
187 be
= self
.BlockExceptions()
189 for i
in xrange(self
.rounds
):