Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from time import time
- from types import GeneratorType
- def bootstrap(f, stack=[]):
- def wrappedfunc(*args, **kwargs):
- if stack:
- return f(*args, **kwargs)
- else:
- to = f(*args, **kwargs)
- while True:
- if type(to) is GeneratorType:
- stack.append(to)
- to = next(to)
- else:
- stack.pop()
- if not stack:
- break
- to = stack[-1].send(to)
- return to
- return wrappedfunc
- a = time()
- @bootstrap
- def fun(n):
- if n == 0:
- yield
- yield fun(n-1)
- yield
- for i in range(10000):
- fun(400)
- b = time()
- print(b-a)
- # took 0.34096312522888184 s in pypy3
Advertisement
Add Comment
Please, Sign In to add comment