This is on an 8-core 2GHz xeon running debian. (Tom Boothby's machine.)
In a clean build of sage-3.0.2:
sage: time x = bernoulli(40000)
CPU times: user 4.19 s, sys: 0.01 s, total: 4.20 s
Wall time: 4.20 s
sage: time x = bernoulli(40000)
CPU times: user 3.18 s, sys: 0.01 s, total: 3.18 s
Wall time: 3.19 s
sage: time x = bernoulli(40000)
CPU times: user 3.18 s, sys: 0.00 s, total: 3.19 s
Wall time: 3.19 s
sage: time x = bernoulli(40000)
CPU times: user 3.18 s, sys: 0.00 s, total: 3.19 s
Wall time: 3.19 s
Then I tried building my own PARI/GP. I first built gmp 4.2.1 with
jason martin's core 2 patches. Then I built pari/gp. I get:
? #
timer = 1 (on)
? x = bernfrac(40000);
time = 1,972 ms.
? x = bernfrac(40000);
time = 1,317 ms.
? x = bernfrac(40000);
time = 1,316 ms.
? x = bernfrac(40000);
time = 1,316 ms.
Why is the sage version three times slower than the gp version?
david
With sage -gp, I get something *in between*:
? x = bernfrac(40000);
time = 3,272 ms.
? x = bernfrac(40000);
time = 2,260 ms.
? x = bernfrac(40000);
time = 2,260 ms.
The banner printout is exactly the same for both gp builds:
GP/PARI CALCULATOR Version 2.3.3 (released)
amd64 running linux (x86-64/GMP-4.2.1 kernel) 64-
bit version
compiled: Jun 9 2008, gcc-4.1.2 20061115 (prerelease)
(Debian 4.1.1-21)
(readline v5.2 enabled, extended help available)
except that my standalone build says "readline not compiled in".
david
Definitely could be conversion overhead. On my machine (warning: I'm
still running the "ridiculously old" Sage 2.10.2) I get
sage: time y = pari(40000).bernfrac()
CPU times: user 4.14 s, sys: 0.00 s, total: 4.14 s
Wall time: 4.15
sage: type(y)
<type 'sage.libs.pari.gen.gen'>
sage: time x = Rational(y)
CPU times: user 1.50 s, sys: 0.00 s, total: 1.50 s
Wall time: 1.50
It looks like the conversion from sage.lib.pari.gen.gen to
sage.rings.rational.Rational just converts y to a string and then parses
the resulting string, which is why this takes so long.
That's true, that definitely accounts for part of it.
But there's still quite a big gap between the times from sage -gp and
from my standalone GP build (see my followup email earlier on this
thread).
I wonder if we are just building GMP incorrectly. That bernfrac()
routine should depend mainly on the speed of long integer
multiplication and division. I am not a GP expert --- how does one
generate large random integers in GP? I could try multiplying them to
see how long that takes.
david
But there's still quite a big gap between the times from sage -gp and
from my standalone GP build (see my followup email earlier on this
thread).
I wonder if we are just building GMP incorrectly. That bernfrac()
routine should depend mainly on the speed of long integer
multiplication and division. I am not a GP expert --- how does one
generate large random integers in GP? I could try multiplying them to
see how long that takes.
david
I wonder if we are just building GMP incorrectly. That bernfrac()routine should depend mainly on the speed of long integer
multiplication and division. I am not a GP expert --- how does one
generate large random integers in GP? I could try multiplying them to
see how long that takes.
Well, I believe that out spkg-install for GMP is potentially broken since we updated to gmp 4.2.2. There are also some potential issues with pre-3.0.3 gmp.spkgs, so I am adding some explicite messages that lets you know that Jason's GMP patch was actually applied.
The last version, so that we could build on cygwin, and also it was needed
for OS X 10.5 64-bit. We will switch to mpir soon, as soon as there is a
release :-)
-- William
Patch up. Please review.
William
Okay, I can confirm that with sage 3.0.1, sage -gp has the same speed
as my standalone GP build. So mostly likely the change to GMP 4.2.2
introduced a speed regression (probably the core 2 patches not being
applied properly).
david
I just noticed that the slowness happens on amd64 as well, so
probably Gaudry's patches are not being applied properly either.
This is on alhambra (2.6GHz opteron):
----------------------------------------------------------------------
| SAGE Version 3.0.1, Release Date: 2008-05-05 |
| Type notebook() for the GUI, and license() for information. |
----------------------------------------------------------------------
sage: x = ZZ.random_element(2^10000000)
sage: y = ZZ.random_element(2^10000000)
sage: time z = x * y
CPU times: user 0.19 s, sys: 0.02 s, total: 0.21 s
Wall time: 0.21
sage: time z = x * y
CPU times: user 0.19 s, sys: 0.01 s, total: 0.20 s
Wall time: 0.20
sage: time z = x * y
CPU times: user 0.20 s, sys: 0.00 s, total: 0.20 s
Wall time: 0.20
----------------------------------------------------------------------
| SAGE Version 3.0.2, Release Date: 2008-05-24 |
| Type notebook() for the GUI, and license() for information. |
----------------------------------------------------------------------
sage: x = ZZ.random_element(2^10000000)
sage: y = ZZ.random_element(2^10000000)
sage: time z = x * y
CPU times: user 0.41 s, sys: 0.00 s, total: 0.41 s
Wall time: 0.42 s
sage: time z = x * y
CPU times: user 0.41 s, sys: 0.00 s, total: 0.41 s
Wall time: 0.41 s
sage: time z = x * y
CPU times: user 0.41 s, sys: 0.00 s, total: 0.41 s
Wall time: 0.41 s
david
Okay, I can confirm that with sage 3.0.1, sage -gp has the same speedas my standalone GP build. So mostly likely the change to GMP 4.2.2introduced a speed regression (probably the core 2 patches not beingapplied properly).Ok, I will investigate and made this a blocker for 3.0.3: #3388As is the gmp.spkg with the Core2 patches and all that fun stuff is agiant mess including the OSX fixes made by William :)Let's hope MPIR is here sooner than later ....I just noticed that the slowness happens on amd64 as well, soprobably Gaudry's patches are not being applied properly either.