#4443: [with patch, with positive review] Massive prime_range speedup, arith*
files cleanup
------------------------------+---------------------------------------------
Reporter: craigcitro | Owner: craigcitro
Type: defect | Status: assigned
Priority: major | Milestone: sage-3.2
Component: basic arithmetic | Resolution:
Keywords: |
------------------------------+---------------------------------------------
Comment (by craigcitro):
Hi John,
Actually, there were a few things that slowed it down. If you look at the
case of `gcd(a,b)`, where `a` and `b` are of type `Integer`, then what we
really need to do is call `a.gcd(b)` and return that result.
In the current version, with these inputs, we:
* check that `b is not None`
* check `hasattr(a,"gcd")`
* return `a.gcd(b)`
In the previous version, we:
* do an import: `from sage.structure.sequence import Sequence`
* create `Sequence((a,b))`
* call `__GCD_sequence`
* call `g = ZZ(0)`
* call `g = g.gcd(a)`
* call `g = g.gcd(b)`
So there are definitely just more steps going on. The two most expensive
are the first two, as I recall. I think that just the import and the
creation of the Sequence were roughly 2/3 of the time spent in `gcd(a,b)`!
You can always check this by setting `a` and `b` and doing `%timeit` from
the command line.
One more note: after the patch, it would actually be '''faster''' to do a
`try`/`except` instead of the `hasattr` in the case of two `Integer`s, by
a constant factor that's roughly 10% for tiny integers. However, it costs
us a factor of 2-3 in the case of Python `int` or `long` -- and since
these classes don't have a `gcd` method, I think this is where the code
gets used most.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/4443#comment:12>
Sage <http://sagemath.org/>
Sage - Open Source Mathematical Software: Building the Car Instead of
Reinventing the Wheel
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en
-~----------~----~----~----~------~----~------~--~---