Which is faster

Class library usage, coding and language questions.
Marianne Jacobsen
Posts: 44
Joined: Fri Oct 26, 2007 1:18 pm

Which is faster

Post by Marianne Jacobsen » Thu Nov 12, 2009 4:20 pm

Assuming an absolute RanoreXpath.

Which is faster - or is there any difference at all?

Element element = absolutXpathhere;
or
form.FindSingle(absolutXpathhere)

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Which is faster

Post by Support Team » Thu Nov 12, 2009 4:35 pm

If it is an absolute RanoreXPath, i.e. a path starting with "/", both statements are equal in speed.

The only difference is that the first statement (the implict assignment from path to element) uses the Adapter.DefaultSearchTimeout whereas the second statement does not use a timeout. The equivalent code for both statements would be:
Element element = absolutXpathhere;
// equals
Element element = Host.Local.FindSingle(absolutXpathhere, Adapter.DefaultSearchTimeout);
Element element = form.FindSingle(absolutXpathhere);
// equals (only for absolute paths!)
Element element = Host.Local.FindSingle(absolutXpathhere);
So, the second statement will search for the RanoreXPath only once, whereas the first statement searches several times until the timeout is reached. That means, if the UI element is already there when the search is started, both statements are equivalent. However, if the element is not there yet and spawns inside the timeout, the first statement will find the element, but the second one will fail, since it searches only once.

Regards,
Alex
Ranorex Support Team
.
Image

Marianne Jacobsen
Posts: 44
Joined: Fri Oct 26, 2007 1:18 pm

Re: Which is faster

Post by Marianne Jacobsen » Thu Nov 12, 2009 4:39 pm

Super - just the reply I was hoping for.

Thanks for the quick respond :D

atom
Posts: 357
Joined: Sun Dec 07, 2008 11:14 pm
Location: Dublin, Ireland

Re: Which is faster

Post by atom » Thu Nov 19, 2009 8:10 pm

This is news to me... why does FindSingle not apply the timeout?
I was under the impression all Find methods did, or should!

Does TryFindSingle apply the timeout?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Which is faster

Post by Support Team » Fri Nov 20, 2009 1:45 pm

atom wrote:Does TryFindSingle apply the timeout?
Only if you specify a timeout.

FindSingle without timeout parameter evaluates the specified path exactly once. No timeout is applied.
FindSingle with timeout parameter evaluates the specified path as long as the timeout is reached or an element is found.
TryFindSingle and Find methods work exactly the same: no timeout is applied if you do not specify a timeout.

The Adapter.DefaultSearchTimeout is only used when you use direct assigning of a path to an adapter/element variable, i.e. when you do not use Find/FindSingle/TryFindSingle:
Text text = "/form[@title='My Form']/text";
If you want to use the Adapter.DefaultSearchTimeout for your Find/FindSingle/TryFindSingle methods, just pass it as a parameter. The following statement is equivalent to the code above:
Text text = Host.Local.FindSingle("/form[@title='My Form']/text", Adapter.DefaultSearchTimeout);
Regards,
Alex
Ranorex Support Team
.
Image

spot
Posts: 8
Joined: Fri Apr 30, 2010 10:16 pm

How to make FindSingle (or similar) faster?

Post by spot » Sat May 01, 2010 12:25 am

Hello,

I've got an container for some tabpages and textboxes on each of these tabpages (in container with different rxpath depth to the tabpage itself). To make it more general I take only one rxpath to the container of all tabpages and then I search for the specific text boxes.
// for example:
// 0. equal
string rxpathToTabContainer = "/form[@controlname='SpForm']/element[@controltypename='MdiClient']/form/container/element/container/container/container/element[@controlname='DetailWorkSpaceDeView']";
// 1. shorter rxpath (only for better understanding)
string rxpathToDevExpressTextBoxOnTabPage1 = rxpathToTabContainer + "/container/container/container/element[@controlname='extId2TextEdit']";
// 2. longer rxpath (only for better understanding)
string rxpathToDevExpressTextBoxOnTabPage2 = rxpathToTabContainer + "/container/container/container/container[@controlname='geocodingContainer1']/container/container[@controlname='gcAddress']/container[@controlname='addressControl']/container/element[@controlname='postCodeTextBox']";

// used code:
Ranorex.Control detailWorkSpace = rxpathToTabContainer ;
string detailItemName1 = "extId2TextEdit";
Ranorex.Control detailItem1 = detailWorkSpace.FindSingle(".//element[@controlname='" + detailItemName1 + ']");
string detailItemName2 = "postCodeTextBox";
Ranorex.Control detailItem2 = detailWorkSpace.FindSingle(".//element[@controlname='" + detailItemName2 + ']");
The time to get detailItem1 (about 1 second) is much more faster then for detailItem2 (about 13 seconds).
So my question: Is there any way to get a fast - or much more faster - FindSingle (or something else)?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Which is faster

Post by Support Team » Mon May 03, 2010 1:55 pm

Hi!
spot wrote:So my question: Is there any way to get a fast - or much more faster - FindSingle (or something else)?
The reason why "detailItemName1" is faster than "detailItemName2" is following. FindSingle with timeout parameter evaluates the specified path as long as the timeout is reached or an element is found. So I think the "detailItemName1" element is on a higher level than "detailItemName2". When you use ".//element" in your code, this means you search the whole tree descending as long you find the item or the timeout is reached.The faster way would be, when you specify the path in more detail for the second item. Or just use the repository items. Repository items in most cases show you the best way to identify an element.

Regards,
Peter
Ranorex Support Team
.
Image

spot
Posts: 8
Joined: Fri Apr 30, 2010 10:16 pm

Re: Which is faster

Post by spot » Tue May 04, 2010 1:00 pm

Okay, when there is no faster way - or faster method - then I must try to work with a path in more detail.

Thank you.