Problem with optimalization

Class library usage, coding and language questions.
zator
Posts: 53
Joined: Wed Jul 04, 2012 1:44 pm
Location: Kraków, POLAND

Problem with optimalization

Post by zator » Wed Sep 19, 2012 12:26 pm

Hi,

I have problem with optimalization of my code. I am trying to write code library for our customized infragistics controls.
My problematic function finds table via xPath, select a row with specified values in specified columns and than click\select it. Additionaly table shows only 50 rows at once and if the row is not found there is a
"->" button witch shows next 50 records.

There is a sample sreenshot of the table:
Image

That's a piece of a code witch i have a problem with:

Code: Select all

...
//finding table
Element grid = Host.Local.FindSingle(xPath, int.Parse(maxCzasSzukania));
Table tab = grid.FindSingle("table[@accessiblerole='Table']");

//stores names of columns, desired values and column's indexes in target table
List<string> columns = new List<string>();
List<string> values = new List<string>();
List<int> indexes = new List<int>();
...
while (true)
{
...
                foreach (Row row in tab.Rows)
                {
                    bool sel = true;
                    for (int i = 0; i < indexes.Count; i++)
                    {
                       //this check last 1s per row !!!
                        if (row.Cells[indexes[i]].Text !=
                            values[i])
                        {
                            sel = false;
                            break;
                        }
...

The problem is with chec in the inner loop, it lasts 1 second per row and it is too long. Can you tell me how should i optimalize it??

The function is quite long, thats why i put only the problematic part. If necessary i can send whole code.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Problem with optimalization

Post by Support Team » Thu Sep 20, 2012 3:31 pm

Hi,

I would use this code:
foreach (Row row in tab.Rows)
			{
				bool sel = true;
				
				IList<Cell> cells = row.Cells;
				
				for (int i = 0; i < indexes.Count; i++)
				{
					
					if (cells[indexes].Text !=
					    values)
					{
						sel = false;
						break;
					}

The row.Cells property is actually a find method, like "row.FindChildren<Cell>();", so in your case Ranorex has to search for the cell elements in each iteration.

Regards,
Markus
Ranorex Support Team