Stefan Behnel, 23.02.2010 15:38: > Lisandro Dalcin, 23.02.2010 15:04: >> On 23 February 2010 10:29, Stefan Behnel wrote: >>> Now, Python 3.x has a new PyDict_GetItemWithError() function that gives us >>> exactly what we want. So my proposal is to not duplicate any implementation >>> details from CPython (again!), but instead provide the speedup only for >>> CPython 3.x. >> I agree. Cython already has many unbenchmarked (is this a word?) >> optimization that no one knows it they are worth the complexity. After >> all, if you still need a 4% speedup when looking up in a dict, just >> use Python C-API, or even implement yourself in C the >> functionality/semantics you need. > > Ok, here is an implementation: > > http://hg.cython.org/cython-devel/rev/8c8994167e1a > > I kept the optimisation in Py2 for str, unicode and int keys, as I expect > their hash and comparison functions to be rather safe, and their use in > dicts to be extremely frequent.
... and I used the micro benchmark that Robert committed to check if there is any difference for the d[key] implementation. I couldn't see any, so I simplified the implementation to use PyObject_GetItem() in Py2. I would even encourage to revert to PyObject_GetItem() completely, also in Py3, given that there seems to be no speedup at all. Stefan _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
