#13400: Use strong caches diligently
-------------------------------+--------------------------------------------
Reporter: nbruin | Owner: robertwb
Type: enhancement | Status: new
Priority: major | Milestone: sage-wishlist
Component: coercion | Resolution:
Keywords: | Work issues:
Report Upstream: N/A | Reviewers:
Authors: | Merged in:
Dependencies: | Stopgaps:
-------------------------------+--------------------------------------------
Comment (by SimonKing):
I experimented a bit further, towards an improved initialisation of finite
fields.
I have already mentioned the idea of caching small fields: The elements of
a small field are cached, hence, why should one not cache the field
itself? That's in [attachment:trac_13400_cache_small_rings.patch]
And I created a short-cut for building ideals in ZZ. That's useful,
because one needs an ideal in ZZ while initialising a finite field. It has
a noticeable effect. With only the first two patches:
{{{
sage: %time L = [GF(p) for p in prime_range(100000)]
CPU times: user 5.25 s, sys: 0.06 s, total: 5.30 s
Wall time: 5.32 s
sage: timeit("ZZ.ideal(5)", number=1000)
1000 loops, best of 3: 84 µs per loop
sage: timeit("ZZ.ideal(5)", number=5000)
5000 loops, best of 3: 90.5 µs per loop
sage: timeit("ZZ.ideal(5)", number=5000)
5000 loops, best of 3: 99.6 µs per loop
sage: timeit("ZZ.ideal(5)", number=5000)
5000 loops, best of 3: 122 µs per loop
sage: timeit("ZZ.ideal(5)", number=5000)
5000 loops, best of 3: 134 µs per loop
}}}
'''Note that the time constantly drops - why is that?'''
With all three patches:
{{{
sage: %time L = [GF(p) for p in prime_range(100000)]
CPU times: user 4.42 s, sys: 0.04 s, total: 4.46 s
Wall time: 4.47 s
sage: timeit("ZZ.ideal(5)", number=1000)
1000 loops, best of 3: 68.7 µs per loop
sage: timeit("ZZ.ideal(5)", number=5000)
5000 loops, best of 3: 76.1 µs per loop
sage: timeit("ZZ.ideal(5)", number=5000)
5000 loops, best of 3: 86.8 µs per loop
sage: timeit("ZZ.ideal(5)", number=5000)
5000 loops, best of 3: 98.1 µs per loop
sage: from sage.rings.finite_rings.integer_mod_ring import quick_ZZ_ideal
sage: timeit("quick_ZZ_ideal(5)", number=1000)
1000 loops, best of 3: 2.89 µs per loop
sage: timeit("quick_ZZ_ideal(5)", number=5000)
5000 loops, best of 3: 2.87 µs per loop
sage: timeit("quick_ZZ_ideal(5)", number=5000)
5000 loops, best of 3: 2.89 µs per loop
sage: timeit("quick_ZZ_ideal(5)", number=5000)
5000 loops, best of 3: 2.86 µs per loop
sage: timeit("quick_ZZ_ideal(5)", number=5000)
5000 loops, best of 3: 2.82 µs per loop
}}}
Hence, the quick way of creating an ideal is much faster, and when using
it in the creation of finite fields, it yields a speed-up of
`(5.25-4.42)/5.25`, which is about 16%.
In a next step, one could try to unravel the `QuotientRing.__init__` in
the finite field initialisation.
Apply trac_13400_subclass_hook_cython.patch
trac_13400_cache_small_rings.patch trac_13400_quick_ZZ_ideal.patch
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/13400#comment:24>
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 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.