#16296: Speed improvements for categories with axioms
-------------------------------------+-------------------------------------
       Reporter:  SimonKing          |        Owner:
           Type:  enhancement        |       Status:  new
       Priority:  major              |    Milestone:  sage-6.3
      Component:  categories         |   Resolution:
       Keywords:  cython             |    Merged in:
  performance categories             |    Reviewers:
        Authors:                     |  Work issues:
Report Upstream:  N/A                |       Commit:
         Branch:                     |  d42dc9c37015b51fac7a089654044dd132c75000
  u/SimonKing/ticket/16296           |     Stopgaps:
   Dependencies:  #10963, #15801     |
-------------------------------------+-------------------------------------

Comment (by SimonKing):

 Another closure occurs in the following definition:
 {{{
 cdef list tailsets = [set(key(O) for O in tail) for tail in tails]
 }}}
 Let's see how to make this a little faster without a closure:
 {{{
 #!python
 def set_test1(list tails):
     cdef list tail
     return [set(O**2 for O in tail) for tail in tails]

 cpdef list set_test2(list tails):
     cdef list tail
     cdef set part_set = set()
     cdef list result = []
     for tail in tails:
         part_set = set()
         for O in tail:
             part_set.add(O**2)
         result.append(part_set)
     return result
 }}}
 yields
 {{{
 sage: L = [[randint(0,10000) for i in range(200)] for j in range(200)]
 sage: set_test1(L) == set_test2(L)
 True
 sage: %timeit set_test1(L)
 100 loops, best of 3: 8.52 ms per loop
 sage: %timeit set_test2(L)
 100 loops, best of 3: 6.51 ms per loop
 }}}
 This time, we do not gain so much, but it is something, and we can make
 the function cpdef then, reducing the calling overhead after (c)importing
 it into another module.

--
Ticket URL: <http://trac.sagemath.org/ticket/16296#comment:15>
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to