# Timing : are hurwitz_zeta values cached? Anonymous

Dear all, It seems the values of hurwitz_zeta are cached in some way. This makes sense, but I couldn't find documentation on that issue, and in particular, on how to clear the cache: I want to time several instances of a script and need to start afresh each time. Here is an ECM:

import sys
from timeit import default_timer as timer
def ECM(prec):
start, CF = timer(), ComplexField(prec)
hurwitz_zeta(s = CF(2), x = CF(0.5))
end = timer()
return end-start

for i in range(0,20):
ECM(3000)

0.10533331300030113
0.011018371998943621
0.011091479000242543
0.0118424979991687
etc...


Then start afresh, get a similar answer. I am pretty sure this system-caching mechanism is explained somewhere but my morning queries drew a blank --

Pointers would be appreciated! Best, Olivier

edit retag close merge delete

Sort by » oldest newest most voted

Regarding the timing issue, the timeit function could be a good choice.

sage: def ECM(prec):
....:     t = timeit(f'C = ComplexField({prec}); hurwitz_zeta(C(2), C(0.5))')
....:     print(f'prec = {prec:3d} --', t)
....:
sage: for i in range(0, 4):
....:     ECM(3000)
....:
prec = 3000 -- 25 loops, best of 3: 9.74 ms per loop
prec = 3000 -- 25 loops, best of 3: 9.8 ms per loop
prec = 3000 -- 25 loops, best of 3: 9.76 ms per loop
prec = 3000 -- 25 loops, best of 3: 9.81 ms per loop


See its documentation:

sage: timeit?


Regarding computing in arbitrary precision, using Arb could be a good choice.

Compare using ComplexField vs ComplexBallField (which uses Arb).

With ComplexField:

sage: C = ComplexField(20)
sage: hurwitz_zeta(C(2), C(0.5))
4.9348


With ComplexBallField, using the zeta method:

sage: C = ComplexBallField(20)
sage: C(2).zeta(a=C(0.5))
[4.93480 +/- 2.40e-6]

more