Stefan Behnel added the comment:

Just for the record, I've compiled Raymond's roadmap version in Cython (with 
only slight changes to make 'self.maxsize' a Py_ssize_t and using an external 
.pxd for typing) and ran Serhiy's benchmark over it (Ubuntu 12.10, 64bit). This 
is what I get in Py3.4:

 0.022  untyped_cy(i)
 0.023  untyped_cy("spam", i)
 0.024  untyped_cy("spam", "spam", i)
 0.106  untyped_cy(a=i)
 0.133  untyped_cy(a="spam", b=i)
 0.152  untyped_cy(a="spam", b="spam", c=i)
 0.033  typed_cy(i)
 0.038  typed_cy("spam", i)
 0.039  typed_cy("spam", "spam", i)
 0.129  typed_cy(a=i)
 0.168  typed_cy(a="spam", b=i)
 0.183  typed_cy(a="spam", b="spam", c=i)

 0.143  untyped_py(i)
 0.234  untyped_py("spam", i)
 0.247  untyped_py("spam", "spam", i)
 0.368  untyped_py(a=i)
 0.406  untyped_py(a="spam", b=i)
 0.425  untyped_py(a="spam", b="spam", c=i)
 0.447  typed_py(i)
 0.469  typed_py("spam", i)
 0.480  typed_py("spam", "spam", i)
 0.745  typed_py(a=i)
 0.783  typed_py(a="spam", b=i)
 0.819  typed_py(a="spam", b="spam", c=i)

Looking at the factors, that's about the same speedup that the dedicated hand 
tuned C implementation presented according to Serhiy's own runs (he reported 
10-25x). Makes me wonder why we should have two entirely separate 
implementations for this.

Here's the lru_cache_class.pxd file I used:

"""
cimport cython

cdef make_key(tuple args, dict kwds, bint typed, tuple kwd_mark)

@cython.final
@cython.internal
cdef class c_lru_cache:
    cdef dict cache
    cdef Py_ssize_t hits
    cdef Py_ssize_t misses
    cdef Py_ssize_t maxsize
    cdef bint typed
    cdef object user_function
    cdef object cache_info_type
    cdef tuple kwd_mark
    cdef list root
"""

----------
nosy: +scoder

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue14373>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to