Opened 5 years ago

# Slow performance when running mpfi in Sage (compairing to Perl)

Reported by: Owned by: akhi major sage-6.6 algebra mpfi, RIF, sagedays 64 nthiery, saliola, merbst, ​zimmerma Akhilesh P. N/A

I have wrote a simple program for addition and multiplication in Sage using mpfi . same thing when I runs in Perl it took much lesser time Example::

```sage: %runfile test3.sage
3.14159265358979323846264338328? is the mpfi number
10.4374148846 seconds time for  1000000 divisions
sage: %runfile test3a.sage
3.14159265358979323846264338328? is the mpfi number
8.87430405617 seconds time for  1000000 additions
sage:

akhi@akhi:~\$ perl test3.pl
[3.1415926535897932384626433832793,3.1415926535897932384626433832825] is the mpfi number
total time =  2 seconds time for  1000000 divisions
akhi@akhi:~\$ perl test3a.pl
[3.1415926535897932384626433832793,3.1415926535897932384626433832825] is the mpfi number
total time =  2 seconds time for  1000000 additions
akhi@akhi:~\$

```

### comment:1 Changed 5 years ago by akhi

• Description modified (diff)

### comment:2 Changed 5 years ago by akhi

• Keywords mpfi RIF sagedays 64 added

### comment:4 Changed 3 years ago by nthiery

Hi Paul,

Akhilesh is sitting next to me here at Sage Days 75. Would you have any insight about the speed difference between Sage and Perl here?

Amitiés,

Nicolas

### comment:5 Changed 3 years ago by tmonteil

When you write `b = n/res`, note that `n` is a Python int and res an element of `RIF`, so Sage has to resolve the coercion to find a common parent, which takes time. Instead, you can transform `n` to an element of `RIF` by writing instead : `b = RIF(n)/res`. The timings should decrease (Debian seems not to distribute MPFI for Perl, so i couldn't do the comparison).

### comment:6 Changed 3 years ago by akhi

I have made the modifications that you suggested but still Perl works much faster