On 09.08.16 00:59, Chris Angelico wrote: > class TooSimpleContextManager: > """Now this time you've gone too far.""" > def __init__(self, func): > self.func = func > def __call__(self): > self.gen = self.func() > return self > def __enter__(self): > next(self.gen) > def __exit__(self, type, value, traceback): > try: next(self.gen) > except StopIteration: pass [...] > My numbers are: > > 0.320 secs > 1.354 secs > slowdown: -4.23x > 0.899 secs > slowdown: -2.81x > 0.831 secs > slowdown: -2.60x > 0.868 secs > slowdown: -2.71x I have got a slowdown 1.74x with TooSimpleContextManager with following implementation of __enter__ and __exit__: def __enter__(self): for res in self.gen: return res raise RuntimeError("generator didn't yield") def __exit__(self, type, value, traceback): for _ in self.gen: raise RuntimeError("generator didn't stop")
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4