How to collect elapsed time of some parts of a script

Asked by Calle Rundgren

comment added after problem solved:
wants to collect elapsed times in his script and output them to a text file for evaluation.
----------------------------------------------------------------------------------------------

I am using time.time() in order to measure the time between checkpionts in my script.

The problem is that i do not know how long time any of the checkpionts will take. Therefore I can not declare my max value to a pre set number like this:

start = time.time()
max = 100.0 #Max value

In order to set max into a variable like [i] and that max therefore is unset and unlimited?

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Calle Rundgren
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

Not really clear what you mean :-(

this e.g. would collect the elapsed times between checkpoints

timeCollect = [time.time()] # time at start
# some time consuming script statements
timeCollect.append(time.time()) # time at checkpoint added to list
# some time consuming script statements
timeCollect.append(time.time()) # time at checkpoint added to list
# some time consuming script statements
timeCollect.append(time.time()) # time at checkpoint added to list
# some time consuming script statements
timeCollect.append(time.time()) # time at checkpoint added to list
# some time consuming script statements
timeCollect.append(time.time()) # time at checkpoint added to list

to get your results e.g.
print "total time=", timeCollect[-1]-timeCollect[0]

and a list of the intermediate elapsed times:
for i in range(len(timeCollect)):
   tt = timeCollect[i+1]-timeCollect[0]
   ts = timeCollect[i+1]-timeCollect[i]
   print "Checkpoint %d: %d total eleapsed -- %d elapsed since previous"%(i+1,tt, ts)

Is it what you want?

Revision history for this message
Calle Rundgren (c-rundgren) said :
#2

Thank you RaiMan, you did understand despite to my bad explanation.

In pseudo I have a couple of functions and I want to collect the time of execution for each function and add it to a .txt before starting the next function.

Since you taught me how to write to files yesterday the answer you gave me now would be enough to perform the task I want to.

While I reading my question again I can really understand you did not get a smack of what I was trying to explain. Well well, a cup of coffee will solve that problem.

Revision history for this message
RaiMan (raimund-hocke) said :
#3

as always:
for both of us it is enjoying to see things are moving ;-)

have fun!