I want to print a timer that starts at 0 when an evaluation begins and stops when the evaluation is completed. I have come up with the following solution using
Dynamic but it's a bit clumsy.
time = AbsoluteTiming[ clock = Dynamic[Clock]; Print["Evaluating... Time: ", Dynamic[clock]]; Pause; ]; clock = time[];
Furthermore, if I want to time several evaluations one after the other, I have to introduce new variables
clock2 etc. so the previous output doesn't get overwritten, which is annoying.
Is there a better way to do this?
Alternatively, I would be happy to only print the evaluation time after the computation has finished. But then I can't get the time to print on the same line as "Evaluating..." becuase
WriteString instead of
Dynamic functionalities of
WriteString does not support.
Reply to Domen's comment:
In the end I guess the purpose is largely aesthetic. I have looked into
PrintTemporary but have not found them useful for this task (of course I could be wrong about that). Say I'm computing a series expansion with
Series that takes a long time to finish. Then I would like to print some text when the computation starts (for example, "Starting series expansion... "). Then, when the computation is finished, I would like to add the evaluation time to this print output such that it reads "Starting series expansion... Time: 10.234" if it took 10.234 seconds. A nice (purely aesthetic) bonus would be if the timer could be shown in real-time, starting at 0 seconds and stopping at 10.234.
As I said above, printing the evaluation time after the evaluation has finished can be done using
WriteString, but I wonder if there is a solution using