Ask Your Question
0

Timing : are hurwitz_zeta values cached?

asked 2020-08-02 05:50:38 -0600

anonymous user

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 flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-08-02 06:22:52 -0600

slelievre gravatar image

updated 2020-08-02 07:14:47 -0600

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]
edit flag offensive delete link more

Comments

Thanks for the syntax in Arb to get the Hurwitz-zeta!

Olivier R. gravatar imageOlivier R. ( 2020-08-02 11:40:17 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-08-02 05:50:38 -0600

Seen: 68 times

Last updated: Aug 02