Using Regions and Match efficiently

Asked by H.C. Lilly III

I am trying to code my Sikuli program as efficiently as possible.

If I have already calculated a match (mat) within a region (reg), then is it quicker to click using the region, or not using the region?

#With region reg:
reg.click(mat, 0)

#Without region:
click(mat, 0)

Logically, I could see it either way. The region will narrow the area of the screen that Sikuli has to work with, and in general makes processing faster. However, if I have already found the match, then does using the region make any difference at all? If not, then I would imagine that the overhead of using the reg object could actually make the click() operation slightly slower.

Which way is recommended?

Thanks!

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:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

This is a historical oddity in the API.

The first parameter to many of the Sikuli functions is PSMRL, which stands for the options
P - Pattern, S - String, M - Match, R - Region, L - Location.

Only for PS it is more efficient to use a restricting region, since this makes the search faster (up to ten times and more):

reg.click(PS) instead of click(PS)

which implicitly binds to SCREEN ( constant object Screen(0) ) and so searches the whole screen.

Using click(MRL) or reg.click(MRL) does not matter in sense of performance, since MRL already define a click point by there object contents (no time consuming search necessary). And in both cases, the click() is bound to a Region object, so no difference (in case click() it is the region SCREEN).
So using reg.click(MRL) only makes sense for documentation/code readability: saying, look I am clicking somewhere inside this region.

Revision history for this message
H.C. Lilly III (hc-lilly) said :
#2

Thanks! I appreciate the information.
H.C.