import timeit import contextlib @contextlib.contextmanager def ctx1(): yield class ctx2: def __enter__(self): pass def __exit__(self, *args): pass t1 = timeit.timeit("with ctx1(): pass", setup="from __main__ import ctx1") t2 = timeit.timeit("with ctx2(): pass", setup="from __main__ import ctx2") print("%.3f secs" % t1) print("%.3f secs" % t2) print("slowdown: -%.2fx" % (t1 / t2)) ...with Python 3.5: 1.938 secs 0.443 secs slowdown: -4.37x I wanted to give it a try rewriting this in C but since @contextmanager has a lot of magic I wanted to ask first whether this 1) is technically possible 2) is desirable. Thoughts? -- Giampaolo - http://grodola.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20160808/d11013cd/attachment.html>
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