.NETGURU
Timing
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngspeed' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Ryan Trudelle-Schwarz (VIP)
What's the best method to use for getting the runtime of an operation?

Thanks, Ryan

Reply to this message...
 
    
Steven A Smith (VIP)
Reposted from Mac Kloberg on another list:

To look at certain aspects of the system, you can use the performance
counters in the Diagnostics namespace.
For raw time trials, you would typically use a timer (System.Threading),
however I've found that the resolution of this class is not very usable for
performance testing (it does milliseconds / is not very good at it).

In Beta1, there used to be a way to access the hardware timer, but that has
been removed in later versions (I guess because of its hardware dependency).
Here's a little class I wrote a while ago, that uses the native windows API
and does self averaging performance timing with overhead compensation:

Public Class HiResPerformanceTimer
Declare Function QueryPerformanceCounter Lib "Kernel32.dll" (ByRef
lpPerformanceCount As UInt64) As Long
Declare Function QueryPerformanceFrequency Lib "Kernel32.dll" (ByRef
lpFrequency As UInt64) As Long

Private _TimerOverhead As Decimal
Private _Precision As Decimal
Private _TickFrequency As UInt64
Private _StartTick As UInt64
Private _CurrentTick As UInt64
Private _StopTick As UInt64
Private _Elapsed As UInt64
Private _IterationCounter As Integer = 1
Private _ElapsedAccu As Decimal
Private _IsRunning As Boolean = False

Private iTmp1 As Integer
Private dTmp1 As Decimal

Public ReadOnly Property TickFrequency() As Decimal
Get
TickFrequency = System.Convert.ToDecimal(_TickFrequency)
End Get
End Property

Public ReadOnly Property TimerOverhead() As Decimal
Get
TimerOverhead = _TimerOverhead
End Get
End Property

Public ReadOnly Property StartTick() As Decimal
Get
StartTick = System.Convert.ToDecimal(_StartTick)
End Get
End Property

Public ReadOnly Property CurrentTick() As Decimal
Get
QueryPerformanceCounter(_CurrentTick)
CurrentTick = System.Convert.ToDecimal(_CurrentTick)
End Get
End Property

Public ReadOnly Property StopTick() As Decimal
Get
StopTick = System.Convert.ToDecimal(_StopTick)
End Get
End Property

Public ReadOnly Property Elapsed() As Decimal
Get
If _IsRunning Then
Elapsed = (CurrentTick - StartTick) / TickFrequency
Else
Elapsed = (StopTick - StartTick - TimerOverhead) /
TickFrequency
End If
End Get
End Property

Public ReadOnly Property AvgElapsed() As Decimal
Get
AvgElapsed = System.Convert.ToDecimal(_ElapsedAccu) /
_IterationCounter
End Get
End Property

Public ReadOnly Property Precision() As Decimal
Get
Precision = 1 / TickFrequency
End Get
End Property

Public ReadOnly Property Iterations() As Integer
Get
Iterations = _IterationCounter
End Get
End Property

Public ReadOnly Property IsRunning() As Boolean
Get
IsRunning = _IsRunning
End Get
End Property

Public Sub Start()
_IsRunning = True
QueryPerformanceCounter(_StartTick)
End Sub

Public Sub [Stop]()
QueryPerformanceCounter(_StopTick)
_IsRunning = False
_IterationCounter += 1
_ElapsedAccu += Elapsed
End Sub

Public Sub AvgReset()
_ElapsedAccu = 0
_IterationCounter = 1
End Sub

Public Sub New()
'Get Tick Frequency
If QueryPerformanceFrequency(_TickFrequency) = 0 Then
Throw New Exception("Error: This hardware platform doesn't
support high-resolution performance counters!")
Else
'Measure our own Overhead across 1000 Start/Stops
dTmp1 = 0
For iTmp1 = 1 To 1000
Start()
[Stop]()
dTmp1 += System.Convert.ToDecimal(_StopTick) -
System.Convert.ToDecimal(_StartTick)
Next
'Get Average Overhead
_TimerOverhead = dTmp1 / Iterations / TickFrequency
'Reset Average Accus
AvgReset()
End If
End Sub
End Class

hth
--
Sincerely,
Mac Kloberg
LIEBHERR AMERICA INC.
http://www.liebherr-us.com

-----Original Message-----
From: Scott Watermasysk [mailto:Click here to reveal e-mail address]
Sent: Sunday, January 13, 2002 12:54 AM
To: aspngfreeforall
Subject: [aspngfreeforall] How to performance test

I have two custom componets that generally do the same function.

For some "raw" time trials, is there anything built into .Net that allows
performance testing?

If it matters, they are both Data Access Layers.

Thanks,
Scott

| ASP.net DOCS = http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP

| ASP.net DOCS = http://www.aspng.com/docs
| [aspngfreeforall] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/aspngfreeforall = JOIN/QUIT
| news://ls.asplists.com = NEWSGROUP

----- Original Message -----
From: "Ryan Trudelle-Schwarz" <Click here to reveal e-mail address>
To: "aspngspeed" <Click here to reveal e-mail address>
Sent: Monday, January 21, 2002 10:58 PM
Subject: [aspngspeed] Timing

[Original message clipped]

Reply to this message...
 
    
Alban Schmid
I use this code to time the performance of all our pages during dev:

global.asax:

****************

<%@ Application src=3D"PerfTiming.cs" Inherits=3D"PerfTiming" %>
<script runat=3D"server">
PerfTiming pt =3D new PerfTiming();
public void Application_OnBeginRequest(Object sender, EventArgs e)
{
    pt.Start();
}

public void Application_OnEndRequest(Object sender, EventArgs e)
{
    double dTimeTaken =3D Math.Round((pt.End())*1000, 2);
    Response.Write("<font face=3D'Arial' size=3D'-2'><br>Performance =
Timing: "+ dTimeTaken.ToString() +" ms</font>");
}         =09
</script>=20

*********************

perftiming.cs

*********************

using System;
using System.Web;
using System.Runtime.InteropServices;

public class PerfTiming : HttpApplication
{
[DllImport("KERNEL32")]
public static extern bool QueryPerformanceCounter(ref Int64 nPfCt);

[DllImport("KERNEL32")]
public static extern bool QueryPerformanceFrequency(ref Int64 =
nPfFreq);

protected Int64 m_i64Frequency;
protected Int64 m_i64Start;

public PerfTiming()
{
QueryPerformanceFrequency(ref m_i64Frequency);
m_i64Start =3D 0;
}

public void Start()
{
QueryPerformanceCounter(ref m_i64Start);
}

public double End()
{
Int64 i64End=3D0;
QueryPerformanceCounter(ref i64End);
return ((i64End - m_i64Start)/(double)m_i64Frequency);
}
}

****************************

-----------------------------------------------------------------
Alban Schmid
Product Development Manager
CNET Channel
Z.I. Rio-Gredon =B7 CH-1806 St-L=E9gier =B7 Switzerland
Tel +41.21.943.03.86 | Fax +41.21.943.03.69
Click here to reveal e-mail address

-----Original Message-----
From: Ryan Trudelle-Schwarz [mailto:Click here to reveal e-mail address]
Sent: Tuesday, January 22, 2002 4:58 AM
To: aspngspeed
Subject: [aspngspeed] Timing

What's the best method to use for getting the runtime of an operation?

Thanks, Ryan

| [aspngspeed] member Click here to reveal e-mail address =3D YOUR ID
| http://www.asplists.com/asplists/aspngspeed.asp =3D JOIN/QUIT
| http://www.asplists.com/search =3D SEARCH Archives

Reply to this message...
 
 
System.Convert
System.EventArgs
System.Math
System.UInt64
System.Web.HttpApplication




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification