How to measure the performance of actions? : How To …

How to measure the performance of actions?

Best practices, code snippets for common functionality, examples, and guidelines.

How to measure the performance of actions?

Postby esac » Sat Sep 25, 2010 3:24 am

I am looking for a way to collect performance statistics on how long each action took. Ideally I would like to remove from that time any time spent in Ranorex itself (searching for forms, windows, images, etc..). Any idea if this can be done? How could I also do this in user code?

Thanks
esac
 
Posts: 3
Joined: Sat Sep 25, 2010 1:59 am

Re: How to measure the performance of actions?

Postby sdaly » Sun Sep 26, 2010 5:56 pm

You could try an approach or similar like this.......

Add the following class....

Public Class perfLogger
	
	Dim startT As System.DateTime 
	Dim endT As System.DateTime 
	Dim span as System.TimeSpan
	
	Public Sub New
	End Sub
	
	Public Sub startLog
		me.startT = now
	End Sub
	
	Public Sub pauseLog
		me.endT = now
		me.span += me.endT - me.startT
	End Sub
	
	Public Function StopLog As system.TimeSpan
		me.pauseLog
		Return me.span
	End Function
	
End Class


Then use as below to start and stop the logger -

Public Sub timeTest
		'create a new logger
		Dim logger as New perfLogger
		'start the logger
		logger.startLog
		
		'code you are measuring here
		
		'pause the logger for Ranorex search time
		logger.pauseLog
		Dim listitem As Ranorex.ListItem = "/desktop[@processname='explorer']/container/list/listitem[@text='Windows Media Player']"
		'start the logger again
		logger.startLog
		listitem.MoveTo
		'report the time
		report.Info("Time",logger.StopLog.totalseconds.tostring())
		
	End Sub



Hope this helps!
Scott
User avatar
sdaly
 
Posts: 213
Joined: Mon May 10, 2010 12:04 pm
Location: Dundee, Scotland

Re: How to measure the performance of actions?

Postby atom » Mon Oct 11, 2010 2:24 pm

A more complicated example is to use a Command design pattern, and in the Invoker/Sender class time the command length
atom
 
Posts: 339
Joined: Mon Dec 08, 2008 12:14 am
Location: Dublin, Ireland

Re: How to measure the performance of actions?

Postby EugeneF » Sat Jan 21, 2012 2:50 am

You may also use "Stopwatch" function in C# :

System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

sw.Reset(); // Reset stopwatch
sw.Start(); // Stopwatch start

you may specify here some condition(s)

for instance -
while (sCell_2_RT == "»")
{
sCell_2_RT = repo.FormFSC_Rater___California_A.RowN2.Cell_2_RT.Text;
}

sw.Stop(); // Stopwatch stop

Thanks.

Eugene
EugeneF
 
Posts: 55
Joined: Fri Jul 29, 2011 1:26 am


Return to How To …

Who is online

Users browsing this forum: No registered users and 0 guests