A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2016-August/145786.html below:

[Python-Dev] Rewrite @contextlib.contextmanager in C

[Python-Dev] Rewrite @contextlib.contextmanager in C [Python-Dev] Rewrite @contextlib.contextmanager in CGiampaolo Rodola' g.rodola at gmail.com
Mon Aug 8 15:33:16 EDT 2016
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>
More information about the Python-Dev mailing list

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