How to get the runtime or CPU time?

Asked by Danny (Dingeman) van der Haven

Hi all!

I would like to time the running time of the simulation at various stages. With this I mean the CPU time or the actual real-world time it take to run the simulation.

I have tried the instructions at https://yade-dem.org/doc/prog.html#timing
But I just get a message that yade.timing does not have the attribute 'timing', even after setting O.timingEnabled=True.
I really just want to use yade.timing.runtime() and write its output to a file.
I don't need a very precise timing or to know how long the engine takes. I just need the current CPU time.

Does YADE have this option or do I need to resort to general Python functions?

With kind regards,
Danny

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Danny (Dingeman) van der Haven
Solved:
Last query:
Last reply:
Revision history for this message
Karol Brzezinski (kbrzezinski) said :
#1

Hi Danny,

It may be a little bit of a workaround, but every periodic engine (e.g. PyRunner) stores the information about the time of the last run. You could use it to track the time of the simulation. For example, if the last engine in the list is PyRunner, you can check:
O.engines[-1].realLast

Cheers,
Karol

Revision history for this message
Jérôme Duriez (jduriez) said :
#2

Hi,

There should be no problem in using timing module (have you "from yade import timing" first ?). Using time.time Python functions is still not a bad idea though as the timing module induces some overhead (see the doc).

Cheers

Revision history for this message
Bruno Chareyre (bruno-chareyre) said :
#3

Python's time.time() is enough in many cases, as long as you don't need per-engine data or nano-second accuracy.

t1 = time.time()
O.run(...)
realTime = time.time() - t1

yade.timing is convenient if you want more granularity in the timings (you probably forgot 'from yade import timing'). You can also introduce your own checkpoints in the source code which will be reflected in the output of yade.timing.stats().

Bruno

Revision history for this message
Danny (Dingeman) van der Haven (dlhvdh) said :
#4

Thank you all! Those suggestions indeed sovled my problem.