Commit bd7a413d authored by Michael Arntzenius's avatar Michael Arntzenius

add microbenchmarks/exceptions_2_ubench.py

parent bcb15381
NUM_ITERS = 100 * 1000
WRAPPER_DEPTH = 10
RECURSE_DEPTH = 0
TRACEBACK_DEPTH = 0
counter = 0
def gtor():
yield 1
raise Exception('bad wrong')
yield 2
def wrapper(n=WRAPPER_DEPTH):
global counter
if n:
try:
wrapper(n-1)
finally:
counter += 1
else:
for x in gtor():
pass
def recurser(n=RECURSE_DEPTH):
if n:
return recurser(n-1)
else:
return wrapper()
def f(niters, traceback_depth=TRACEBACK_DEPTH):
global counter
if traceback_depth:
f(niters, traceback_depth - 1)
else:
for i in xrange(niters):
try:
recurser()
except Exception:
counter = 0
f(NUM_ITERS)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment