Home All Groups Group Topic Archive Search About
Author
20 Mar 2006 8:52 PM
cj
I need to get the time it took for a process to run.  It should be less
than a second but may be up to 5 seconds.

I'm used to showing how many seconds something has taken by:

starttime = now()
..
..
finishtime = now()
label1.text = DateDiff(DateInterval.Second, starttime, finishtime)

but I don't think this will show me fractions of a second.  How can I
get it to display fractions of a second?

Author
20 Mar 2006 8:56 PM
Marina Levit [MVP]
You could do something like:

label1.text = finishtime.Subtract(starttime).TotalSeconds.ToString()

Show quoteHide quote
"cj" <cj@nospam.nospam> wrote in message
news:eLGwkAGTGHA.2276@tk2msftngp13.phx.gbl...
>I need to get the time it took for a process to run.  It should be less
>than a second but may be up to 5 seconds.
>
> I'm used to showing how many seconds something has taken by:
>
> starttime = now()
> .
> .
> finishtime = now()
> label1.text = DateDiff(DateInterval.Second, starttime, finishtime)
>
> but I don't think this will show me fractions of a second.  How can I get
> it to display fractions of a second?
Author
20 Mar 2006 9:24 PM
cj
Sounds good, I'll give it a try.  Thanks, Marina.

Marina Levit [MVP] wrote:
Show quoteHide quote
> You could do something like:
>
> label1.text = finishtime.Subtract(starttime).TotalSeconds.ToString()
>
> "cj" <cj@nospam.nospam> wrote in message
> news:eLGwkAGTGHA.2276@tk2msftngp13.phx.gbl...
>> I need to get the time it took for a process to run.  It should be less
>> than a second but may be up to 5 seconds.
>>
>> I'm used to showing how many seconds something has taken by:
>>
>> starttime = now()
>> .
>> .
>> finishtime = now()
>> label1.text = DateDiff(DateInterval.Second, starttime, finishtime)
>>
>> but I don't think this will show me fractions of a second.  How can I get
>> it to display fractions of a second?
>
>
Author
21 Mar 2006 8:58 AM
R. MacDonald
Hello, cj,

Re:
>>> I need to get the time it took for a process to run.  It should be
>>> less than a second but may be up to 5 seconds.

Also, be aware that using "Now" will become very inaccurate if the
durations that you are measuring are less than 10-30 milliseconds.
Depending on your need for accuracy, you might want to investigate the
QueryPerformanceCounter API.

Cheers,
Randy


cj wrote:
Show quoteHide quote
> Sounds good, I'll give it a try.  Thanks, Marina.
>
> Marina Levit [MVP] wrote:
>
>> You could do something like:
>>
>> label1.text = finishtime.Subtract(starttime).TotalSeconds.ToString()
>>
>> "cj" <cj@nospam.nospam> wrote in message
>> news:eLGwkAGTGHA.2276@tk2msftngp13.phx.gbl...
>>
>>> I need to get the time it took for a process to run.  It should be
>>> less than a second but may be up to 5 seconds.
>>>
>>> I'm used to showing how many seconds something has taken by:
>>>
>>> starttime = now()
>>> .
>>> .
>>> finishtime = now()
>>> label1.text = DateDiff(DateInterval.Second, starttime, finishtime)
>>>
>>> but I don't think this will show me fractions of a second.  How can I
>>> get it to display fractions of a second?
>>
>>
>>
Author
21 Mar 2006 10:03 AM
Cor Ligthert [MVP]
Randy,

There is no accurate method on a Windows OS computer, which is not
completely isolated from the outer-world, even not that API.

Therefore I used in version 1.x forever environment.timerticks while there
is now in 2.0 the stopwatch class

http://msdn2.microsoft.com/en-us/library/ebf7z0sw(VS.80).aspx

Cor
Author
21 Mar 2006 10:34 AM
R. MacDonald
Hi, Cor,

Thanks for the update and the link.  Yes, there is no "absolute"
accuracy -- even on a real-time OS.  (And Windows doesn't even pretend
to be real-time.)

I guess that the real question is: "Is it accurate enough?".  I think
that the Now function might not be accurate enough for the needs of the
OP -- but then again, it might.  QueryPerformanceCounter will probably
be accurate enough, but it is not available on all systems and there are
a few subtleties involved in using it.

It looks like StopWatch is basically a wrapper for whatever tool
provides the greatest accuracy. (This is probably
QueryPerformanceCounter on most systems, but TickCount on others).  This
is certainly easier than having to code for both possibilities like I
had to do in VB6.  I'm still using the earlier version.  Too bad it's
not available there too.

Groetjes,
Randy


Cor Ligthert [MVP] wrote:

Show quoteHide quote
> Randy,
>
> There is no accurate method on a Windows OS computer, which is not
> completely isolated from the outer-world, even not that API.
>
> Therefore I used in version 1.x forever environment.timerticks while there
> is now in 2.0 the stopwatch class
>
> http://msdn2.microsoft.com/en-us/library/ebf7z0sw(VS.80).aspx
>
> Cor
>
>