Getting time of matching operation

Asked by Alex Lunyov

Hi!

I need to get the time in milliseconds of matching (if it was successful).
When I print a match result I get something like this:

a = find(myimage)
print a
>>M[1014,305 169x155]@S(S(0)[0,0 1920x1080]) S:1,00 C:1098,382 [453 msec]

I need function to get time:
print a.getTime()
>>453

Is it possible without converting to str and parsing?

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:

This question was reopened

Revision history for this message
Alex Lunyov (lunyov-av) said :
#1

OK, I have just exctracted the list of methods of Match and got .getTime() that is exactly what I need.

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

Match.getTime()
... returns the time in milliseconds of the elapsed time of the corresponding find action including loading the image and the (in case repetetive) search for the image.

In Python it is an integer value, that can be used for whatever you want appropriately.

duration = a.getTime()
durationInSeconds = duration/1000
print durationInSeconds

print automatically converts to printable string values if possible.

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

LOL, not as fast as you are ;-)
all the best

Revision history for this message
Alex Lunyov (lunyov-av) said :
#4

Thanks Raiman! But I still need some help. So, when the image is right on the screen and it matches during first scan, the result is like this:

getTime()
>>15
print a
M[1014,305 169x155]@S(S(0)[0,0 1920x1080]) S:1,00 C:1098,382 [15 msec]
# 15 and 15 msec

And when I do some clicks to open image and it matches during next scan iterations, the result of getTime is different:

getTime()
>>33
print a
M[1014,305 169x155]@S(S(0)[0,0 1920x1080]) S:1,00 C:1098,382 [15 msec]
# 33 and 15 msec

So, I need the whole time, not the time of successful scan (is it right definition of getTime?)
I could try to get a difference of system time before and after find operation but I wonder if there are internal timing function.

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

ok, I will check in the code and tell you.

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

this is it:

--- getTime()
... reports the total milliseconds including eventual repetitive scans (waiting for the image to appear)

--- in the Match.toString() message
... like: M[1014,305 169x155]@S(S(0)[0,0 1920x1080]) S:1,00 C:1098,382 [15 msec]
the time in the trailing brackets show the duration of the last scan.

... and be aware: 1.1.1 has the default behavior, to first look in the place where an image was last found in case it is searched again (which usually speeds up workflow repetitions a lot). Only if it is no longer in place, it is searched in the given region. So this effect might also lead to different timing patterns.
If you do not want this behavior:
Settings.CheckLastSeen = False

Revision history for this message
Alex Lunyov (lunyov-av) said :
#7

Thanks a lot for the answer. May be I didn't understand something, but why does getTime() always report a number less then 1000 while I wait for the visual for ten seconds or more (I usually get getTime=200, 300 or so in case matching picture appeared in 10 seconds). I expected getTime > 10000. What's wrong?
P.S. Find function runs immediately in my script after I press Run button. So, it performs scans during >10 seconds before it gets success match.

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

Uuups, I will check.
Thanks for not giving up ;-)

Revision history for this message
Alex Lunyov (lunyov-av) said :
#9

Try to do my best to improve the project as we all do :-) The correct function getTime will make my code more robust in the first seconds of starting.

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

I fixed it - it was indeed bullshit ;-)

see the new nightly in about 2 hours.

thanks for your persistence.
tests and feedback would be highly appreciated.

Revision history for this message
Alex Lunyov (lunyov-av) said :
#11

Great, the bug flyed out!)

680923
M[1029,196 796x653]@S(S(0)[0,0 1920x1080]) S:1,00 C:1427,522 [680923 msec]

I made several timing tests and all were successful.

Solved!

Revision history for this message
Alex Lunyov (lunyov-av) said :
#12

Thanks RaiMan, that solved my question.