het_fadia

Untitled

Jun 15th, 2021
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. from time import time
  2. from types import GeneratorType
  3.  
  4.  
  5. def bootstrap(f, stack=[]):
  6. def wrappedfunc(*args, **kwargs):
  7. if stack:
  8. return f(*args, **kwargs)
  9. else:
  10. to = f(*args, **kwargs)
  11. while True:
  12. if type(to) is GeneratorType:
  13. stack.append(to)
  14. to = next(to)
  15. else:
  16. stack.pop()
  17. if not stack:
  18. break
  19. to = stack[-1].send(to)
  20. return to
  21.  
  22. return wrappedfunc
  23. a = time()
  24.  
  25. @bootstrap
  26. def fun(n):
  27. if n == 0:
  28. yield
  29. yield fun(n-1)
  30. yield
  31.  
  32.  
  33. for i in range(10000):
  34. fun(400)
  35. b = time()
  36. print(b-a)
  37. # took 0.34096312522888184 s in pypy3
Advertisement
Add Comment
Please, Sign In to add comment