#18304: Integer and Rational comparisons
-------------------------------------+-------------------------------------
       Reporter:  vdelecroix         |        Owner:
           Type:  enhancement        |       Status:  needs_work
       Priority:  major              |    Milestone:  sage-6.9
      Component:  performance        |   Resolution:
       Keywords:                     |    Merged in:
        Authors:  Vincent Delecroix  |    Reviewers:
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
  u/vdelecroix/18304                 |  e03a26e63dd50f79fc7ada885daefd8c9970c482
   Dependencies:                     |     Stopgaps:
-------------------------------------+-------------------------------------
Changes (by vdelecroix):

 * status:  needs_review => needs_work


Old description:

> Comparing integers is very fast, comparing rationals is very fast but
> comparing integer with rational is about 5x slower:
> {{{
> sage: a = 1; b = 18
> sage: timeit("a < b", number=500000, repeat=100)
> 500000 loops, best of 100: 64.3 ns per loop
> sage: a = QQ(1); b = QQ(18)
> sage: timeit("a < b", number=500000, repeat=100)
> 500000 loops, best of 100: 84 ns per loop
> sage: a = 1; b = QQ(18)
> sage: timeit("a < b", number=500000, repeat=100)
> 500000 loops, best of 100: 405 ns per loop
> }}}
>
> With the branch applied, it gets better
> {{{
> sage: a = 1; b = 18
> sage: timeit("a < b", number=500000, repeat=100)
> 500000 loops, best of 100: 64 ns per loop
> sage: a = QQ(1); b = QQ(18)
> sage: timeit("a < b", number=500000, repeat=100)
> 500000 loops, best of 100: 65.6 ns per loop
> sage: a = 1; b = QQ(18)
> sage: timeit("a < b", number=500000, repeat=100)
> 500000 loops, best of 100: 87.1 ns per loop
> }}}
>
> Upstream mpir pull request for the `mpq_cmp_mpz` function:
>
>     [https://github.com/wbhart/mpir/pull/157
> https://github.com/wbhart/mpir/pull/157]
>
> Warning: if you pull the branch and run `make` then you will likely
> rebuild your whole Sage!

New description:

 DISCLAIMER: this ticket is waiting from two upstream modifications (GMP
 and mpir). Namely the creation of the function `mpq_cmp_z(mpq_t, mpz_t)`.

 Comparing integers is very fast, comparing rationals is very fast but
 comparing integer with rational is about 5x slower:
 {{{
 sage: a = 1; b = 18
 sage: timeit("a < b", number=500000, repeat=100)
 500000 loops, best of 100: 64.3 ns per loop
 sage: a = QQ(1); b = QQ(18)
 sage: timeit("a < b", number=500000, repeat=100)
 500000 loops, best of 100: 84 ns per loop
 sage: a = 1; b = QQ(18)
 sage: timeit("a < b", number=500000, repeat=100)
 500000 loops, best of 100: 405 ns per loop
 }}}

 With the branch applied, it gets better
 {{{
 sage: a = 1; b = 18
 sage: timeit("a < b", number=500000, repeat=100)
 500000 loops, best of 100: 64 ns per loop
 sage: a = QQ(1); b = QQ(18)
 sage: timeit("a < b", number=500000, repeat=100)
 500000 loops, best of 100: 65.6 ns per loop
 sage: a = 1; b = QQ(18)
 sage: timeit("a < b", number=500000, repeat=100)
 500000 loops, best of 100: 87.1 ns per loop
 }}}

 Upstream mpir pull request for the `mpq_cmp_mpz` function:

     [https://github.com/wbhart/mpir/pull/157
 https://github.com/wbhart/mpir/pull/157]

 Warning: if you pull the branch and run `make` then you will likely
 rebuild your whole Sage!

--

Comment:

 Replying to [comment:17 mmezzarobba]:
 > Replying to [comment:16 vdelecroix]:
 > > You are right, I need to also patch gmp in order to make Sage works.
 Another option is to wait for upstream upgrading from both GMP and mpir.
 What do you think? I mostly wanted to test it.
 >
 > I'd wait.

 Looks more reasonable to me as well (I do not like to patch upstream). So
 I will push harder upstream to have these functions in the next releases.

--
Ticket URL: <http://trac.sagemath.org/ticket/18304#comment:18>
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