#14615: cythonize lazy_atrtibute
-------------------------------+--------------------------------------------
       Reporter:  nbruin       |         Owner:  tbd      
           Type:  enhancement  |        Status:  new      
       Priority:  major        |     Milestone:  sage-5.10
      Component:  performance  |    Resolution:           
       Keywords:               |   Work issues:           
Report Upstream:  N/A          |     Reviewers:           
        Authors:               |     Merged in:           
   Dependencies:               |      Stopgaps:           
-------------------------------+--------------------------------------------

Comment (by nbruin):

 As a comparison, with
 {{{
 cython("""
 from sage.misc.lazy_attribute import lazy_attribute
 cdef class T(object):
     cdef public __cached_methods
     @lazy_attribute
     def t(self):
         return 10
     def s(self):
         return 10
 """)
 }}}
 we get
 {{{
 sage: t=T()
 sage: %timeit t.t
 10000000 loops, best of 3: 82.6 ns per loop
 }}}
 and with the old `lazy_attribute` we get:
 {{{
 1000000 loops, best of 3: 517 ns per loop
 }}}
 This puts (cached) lazy attribute access in a factor of 2 of accessing
 `cdef public` members:
 {{{
 sage: %timeit t.__cached_methods
 10000000 loops, best of 3: 42 ns per loop
 }}}
 Of course, if there's a dictionary available, the code for
 `@lazy_attribute` doesn't matter for cached retrieval. To get a bit of an
 idea of non-cached access costs with patch:
 {{{
 sage: %timeit T()
 10000000 loops, best of 3: 78.4 ns per loop
 sage: %timeit T().t
 1000000 loops, best of 3: 1.15 us per loop
 }}}
 versus without patch:
 {{{
 sage: %timeit T().t
 100000 loops, best of 3: 3.76 us per loop
 }}}
 so in this case there is still a reduction in overhead.Incidentally, we
 have:
 {{{
 sage: %timeit t.s()
 10000000 loops, best of 3: 59.5 ns per loop
 }}}
 so the overhead on calling the wrapped function is really quite small
 (i.e., we're really just measuring the costs that `lazy_attribute` adds.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/14615#comment:1>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to