Amaury Forgeot d'Arc added the comment:

> What's strange is that calling __enter__ and __exit__ in a 
> try/finally block brings the speed back to the faster 'with' speed, 
> even though they call the same C functions

Looking carefully at the code, there are two reasons for this:
- LockType has no methods! try "dir(thread.LockType)". Instead, LockType
defines a tp_getattr which does a *linear* search in a PyMethodDef
array. First items are served faster...
- After converting this to use the usual tp_methods slot, there is still
a performance difference, due to the fact that release() is a
METH_NOARGS method, while __exit__() uses METH_VARARGS.

Phew.

__________________________________
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue2179>
__________________________________
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to