Willie,
| the point is that my application logs the time used to run a certain
| database call, and no average can me calculated.
OK. I believe my comment still stands.
My first point is you need to use QueryPerformanceCounter or another higher
resolution timer (the multiple media timer for example) to time the database
call. I believe one or more of the articles I gave discuss the various high
resolution timers available.
My second point is that an individual database call may be "off" (because of
other processes running & possibly the network itself), but when you average
the times of 100 or 1000 or more database calls, it will be increasingly
more "reliable"...
I would recommend QueryPerformanceCounter as it has the same resolution as
System.Diagnostics.PerformanceCounter. In addition to (instead of?) logging
the time of a certain database call, I would define a number of
PerformanceCounters (aka Instrumentation) that tracked items such as:
- database calls per second
- seconds per database call
- number of database calls
- total seconds of all database calls
- number of "transactions" (unit of work)
- number of database calls per "transaction"
- seconds per "transaction"
- "transactions" per second
- total seconds of all "transactions"
Where an individual "transaction" makes one or more database calls. For
example saving a shopping cart is the transaction. The act of saving the
shopping cart will call the database for the shopping cart shipping/billing
info (the header), plus call the database once for each item in the shopping
cart (the detail).
Generally you only need one of "calls per second" & "seconds per call",
depending on the what the average length of the item being measured is.
Sometimes I include both as its not obvious which one will be more useful.
By defining PerformanceCounters you are able to use tools such as PerfMon
(Start - Control Panel - Administrative Tools - Performance') to see how
your app is performing overall. Having the log may help identify specific
problems once PerfMon has identified a problem...
Post if you would like links on Performance Counters & Instrumentation in
..NET.
Hope this helps
Jay
"Willie jan" <un*****@unkown.com> wrote in message
news:43***********************@news.euronet.nl...
| the point is that my application logs the time used to run a certain
| database call, and no average can me calculated. Now something they get a
| value, and sometimes a 0. That's my problem right now.
| When the call is for instance 30-60 ms, it's no problem with the ticks not
| showing the right amount because the longer the calls takes, the less
offset
| in % is there.
| But when a call that is made is 5ms than 1 less or more is 20%...
|
| Willie.
|
|
| "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> schreef in
bericht
| news:Op**************@TK2MSFTNGP14.phx.gbl...
| > Willie,
| > I should add: as Cor mentions.
| >
| > Using Now.Ticks or QueryPerformanceCounter or any other timing method in
| > Windows is not going to be reliable, as there are other processes that
are
| > running, that can change the outcome of the timing. I believe one or
more
| > of
| > the articles I gave discuss this "interference" of other processes.
| >
| >
| > Normally I run my test 5 or more times & average the results.
| >
| > Hope this helps
| > Jay
| >
| > "Willie jan" <un*****@unkown.com> wrote in message
| > news:43***********************@news.euronet.nl...
| > | the problem i have is that the now.ticks is not relayable.
| > | the first click returns 0, the second returns 2.6ms
| > | i will check out your QueryPerformanceCounter
| > |
| > | thanks.
| > |
| > | "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> schreef in
| > bericht
| > | news:O6**************@TK2MSFTNGP09.phx.gbl...
| > | > Willie,
| > | > As the others suggest, you should use Long or DateTime to store T.
| > | >
| > | > DateTime has a "resolution" of 100-nanoseconds, its precession can
| > vary,
| > | > in
| > | > that although it is based on units of 100-nanosecond its resolution
or
| > | > precision is based on the system timer (which may be as course as
..01
| > | > seconds)
| > | >
| > | > QueryPerformanceCounter has a resolution of nanoseconds or smaller
| > (its
| > | > precession is the QueryPerformanceFrequency value). Its based on a
| > | > "high-resolution performance counter", which I understand is a
special
| > | > hard
| > | > ware counter on some CPUs...
| > | >
| > | > Tickcount has a resolution of microseconds.
| > | >
| > | > There is an MSDN Magazine article that discusses timing blocks of
| > code,
| > | > however I am having trouble finding it right now, it may be the
third
| > link
| > | > below, however it doesn't feel right...
| > | >
| > | > Use QueryPerformanceCounter to Time code in VB.NET:
| > | >
http://support.microsoft.com/default...b;en-us;306978
| > | >
| > | > Not sure if the following will help or not:
| > | >
| > | > Comparing the Timer Classes in the .NET Framework Class Library
| > | >
| >
http://msdn.microsoft.com/msdnmag/is...T/default.aspx
| > | >
| > | > Implement a Continuously Updating, High_Resolution Time Provider for
| > | > Windows
| > | >
| >
http://msdn.microsoft.com/msdnmag/is...r/default.aspx
| > | >
| > | >
| > | > I normally use QueryPerformanceCounter as its in the units used by
| > | > Performance Counters:
| > | >
| > | > Something like:
| > | >
| > | > Declare Function QueryPerformanceCounter Lib "Kernel32" (ByRef
| > counter
| > | > As Long) As Boolean
| > | > Declare Function QueryPerformanceFrequency Lib "Kernel32" (ByRef
| > | > frequency As Long) As Boolean
| > | >
| > | >
| > | > ' set some time var
| > | > Dim start, finish, frequency As Long
| > | > QueryPerformanceFrequency(frequency)
| > | > QueryPerformanceCounter(start)
| > | >
| > | > ' work
| > | >
| > | > QueryPerformanceCounter(finish)
| > | > Dim time As TimeSpan = TimeSpan.FromSeconds((finish - start)
/
| > | > frequency)
| > | >
| > | > Alternatively you can use DateTime:
| > | >
| > | > ' set some time var
| > | > Dim start, finish As DateTime
| > | > start = DateTime.Now
| > | >
| > | > ' work
| > | >
| > | > finish = DateTime.Now
| > | > Dim time As TimeSpan = finish.Subtract(start)
| > | >
| > | > A third alternative would be to use "Ticks"
| > | >
| > | > ' set some time var
| > | > Dim start, finish As Integer
| > | > start = Environment.TickCount
| > | >
| > | > ' work
| > | >
| > | > ' set second time var and comapre to get result
| > | > finish = Environment.TickCount
| > | > Dim time As TimeSpan = TimeSpan.FromMilliseconds(finish -
| > start)
| > | >
| > | > My understanding is that QueryPerformanceCounter will normally be a
| > higher
| > | > resolution then Environment.TickCount, however
QueryPerformanceCounter
| > may
| > | > not be available.
| > | >
| > | > VB.NET 2005 (aka Whidbey, due out later in 2005) simplifies the
choice
| > by
| > | > providing a System.Diagnostics.Stopwatch class that will
automatically
| > | > choose between QueryPerformanceCounter & Environment.TickCount...
| > | >
| > | >
http://lab.msdn.microsoft.com/vs2005/
| > | >
| > | >
http://msdn2.microsoft.com/library/ebf7z0sw.aspx
| > | >
| > | > Hope this helps
| > | > Jay
| > | >
| > | >
| > | > "Willie jan" <un*****@unkown.com> wrote in message
| > | > news:43***********************@news.euronet.nl...
| > | > | place this behind a button that fills a listbox.
| > | > | as you will see the time is now and then 0 or filled
in????????????
| > | > | by hitting the button.
| > | > |
| > | > | is there a way to determine the real elapsed time?
| > | > |
| > | > | thanks, Willie
| > | > |
| > | > | Dim T As Double
| > | > |
| > | > | T = Now.Ticks
| > | > |
| > | > | System.Threading.Thread.Sleep(3)
| > | > |
| > | > | T = Now.Ticks - T
| > | > |
| > | > | ListBox1.Items.Insert(0, T.ToString("0000000000000000"))
| > | > |
| > | > |
| > | >
| > | >
| > |
| > |
| >
| >
|
|