ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 02 Aug 2020 12:50:38 +0200Timing : are hurwitz_zeta values cached?https://ask.sagemath.org/question/52806/timing-are-hurwitz_zeta-values-cached/ 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, OlivierOlivier R.Sun, 02 Aug 2020 12:50:38 +0200https://ask.sagemath.org/question/52806/How to properly time Sage computations?https://ask.sagemath.org/question/41284/how-to-properly-time-sage-computations/I have written a Sage code that performs some calculations with elliptic curves, and I want to get how much time it took to finish the calculations. I saw that there is already a function called [timeit](https://doc.sagemath.org/html/en/reference/misc/sage/misc/sage_timeit_class.html), but what I see is that it basically times the given command. Instead what I need is that I want to time the execution of certain code block (for example, a loop). Assuming, I have a code segment as this:
for i in range(0, 100):
# Do some calculations...
How can I get how much time it took to execute the code block (in this case the whole loop)?ninhoTue, 27 Feb 2018 18:08:14 +0100https://ask.sagemath.org/question/41284/Timing cached functionshttps://ask.sagemath.org/question/8289/timing-cached-functions/I have defined a recursive function that call itself several times, often asking for the same result that was previously computed. In this setting, defining the function as cached makes perfect sense.
But when i try to timeit, i always get very low timings (i assume the function is computed once and then the cache is called several times, making the average timing very low). I could define the function as non cached, but in that case i can not measure how much i gain by caching the intermediate calls from the function to itself.
Is there some way to say timeit to empty the cache each time the function is run?mmarcoTue, 23 Aug 2011 14:01:45 +0200https://ask.sagemath.org/question/8289/