#20681: Cythonize the special methods in the categories that handle coercion in
arithmetic
-------------------------------------+----------------------------
       Reporter:  nthiery            |        Owner:
           Type:  enhancement        |       Status:  needs_review
       Priority:  major              |    Milestone:  sage-7.3
      Component:  categories         |   Resolution:
       Keywords:  performance        |    Merged in:
        Authors:  Nicolas M. Thiéry  |    Reviewers:
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
   Dependencies:                     |     Stopgaps:
-------------------------------------+----------------------------
Changes (by nthiery):

 * status:  new => needs_review


Old description:



New description:

 Recall that the Sage categories provide implementations for Python's
 special methods for the basic arithmetic operations (e.g. `__mul__`,
 `__add__`), that dispatch to the coercion model or call Sage's special
 methods (e.g. `_mul_`, `_add_`) for the internal operations.

 Before this ticket, this indirection induces an overhead of roughly
 500ns:
 {{{
 sage: S = Semigroups().example()
 sage: x = S.an_element()

 sage: sage: %timeit [x*x for i in range(1000)]
 1000 loops, best of 3: 1.21 ms per loop
 sage: sage: %timeit [x.__mul__(x) for i in range(1000)]
 1000 loops, best of 3: 1.12 ms per loop
 sage: sage: %timeit [x._mul_(x) for i in range(1000)]
 1000 loops, best of 3: 643 µs per loop
 }}}
 (the average timing don't vary much if we try again)

 After this ticket, which Cythonize those methods, the overhead is
 reduced to roughly 260ns, which is a speedup by a factor of 2:
 {{{
 sage: %timeit [x*x for i in range(1000)]
 1000 loops, best of 3: 929 µs per loop
 sage: %timeit [x.__mul__(x) for i in range(1000)]
 1000 loops, best of 3: 884 µs per loop
 sage: %timeit [x._mul_(x) for i in range(1000)]
 1000 loops, best of 3: 624 µs per loop
 }}}

--

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

Reply via email to