This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jyasskin
Recipients amaury.forgeotdarc, belopolsky, benjamin.peterson, christian.heimes, collinwinter, jcea, jyasskin, ncoghlan, nnorwitz, rhettinger
Date 2008-03-09.17:03:39
SpamBayes Score 0.12672547
Marked as misclassified No
Message-id <1205082221.37.0.755501851736.issue2179@psf.upfronthosting.co.za>
In-reply-to
Content
Thanks Nick and Amaury!

Amaury, what times are you seeing? It could be a just-gcc speedup, but I
wouldn't have thought so since the patch eliminates 2 times around the
eval loop. It could be that the overhead of WITH_CLEANUP is high enough
to drown out those iterations. You had mentioned optimizing the
PyObject_CallFunctionObjArgs() call before. If you're still seeing with
significantly slower than try, that's probably the right place to look.

Here are my current timings. To avoid the lock issues, I wrote
simple_cm.py containing:

class CM(object):
    def __enter__(self):
        pass
    def __exit__(self, *args):
        pass

$ ./python.exe -m timeit -s 'import simple_cm; cm = simple_cm.CM()'
'with cm: pass'
1000000 loops, best of 3: 0.885 usec per loop
$ ./python.exe -m timeit -s 'import simple_cm; cm = simple_cm.CM()'
'cm.__enter__()' 'try: pass' 'finally: cm.__exit__()'
1000000 loops, best of 3: 0.858 usec per loop

If __exit__ doesn't contain *args (making it not a context manager), the
try/finally time goes down to:
$ ./python.exe -m timeit -s 'import simple_cm; cm = simple_cm.CM()'
'cm.__enter__()' 'try: pass' 'finally: cm.__exit__()'
1000000 loops, best of 3: 0.619 usec per loop

I think in theory, with could be slightly faster than finally with the
same argument list, but it's pretty close now.
History
Date User Action Args
2008-03-09 17:03:41jyasskinsetspambayes_score: 0.126725 -> 0.12672547
recipients: + jyasskin, nnorwitz, collinwinter, rhettinger, jcea, amaury.forgeotdarc, ncoghlan, belopolsky, christian.heimes, benjamin.peterson
2008-03-09 17:03:41jyasskinsetspambayes_score: 0.126725 -> 0.126725
messageid: <1205082221.37.0.755501851736.issue2179@psf.upfronthosting.co.za>
2008-03-09 17:03:40jyasskinlinkissue2179 messages
2008-03-09 17:03:39jyasskincreate