• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1747
  • Last Modified:

time in vb.net

I just want to know what is the minimum amount of time difference we can measure by using vb.net
its like i send a packet and then receive it.
i want to calculate the time difference. i guess it mightl be 1 millisecond or lower.

is their any way to get the time difference less than 1 milli second


thanx in advance
---prashanth
0
prashanth_gurijala
Asked:
prashanth_gurijala
4 Solutions
 
iboutchkineCommented:
I think that minimum is a tick

    Dim T1, T2 As System.DateTime

        T1 = Now
'do something
        T2 = Now
        MsgBox("It took " & ((T2.Ticks - T1.Ticks) / 10000).ToString & " msecs to sort array")
0
 
rdrunnerCommented:
you could try "timer()"

This will allow you to get the seconds passed since midnight... But i dont know whats the smalles value for it
0
 
rdrunnerCommented:
Now will only return down to the second :(
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
acharbonneauCommented:
There is the tick, which is 100 nanoseconds
0
 
GohdanTheMoblinCommented:
Looking over the documentation for the DateTime.Now property, it seems that the resolution depends on the System timer.

DateTime.Now: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatetimeclassnowtopic.asp

This means that past NT 3.5, you only have 10ms of guaranteed resolution.  An alternative is the Environment.TickCount property, but it claims it is derived from the System Timer as well and additionally its resolution "cannot be less than 500 milliseconds", so DateTime.Now seems best.

Environment.TickCount: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemenvironmentclasstickcounttopic.asp

To measure time as accurately as possible, use the TimeSpan class and its properties.  Here's a simple example that shows the number of milliseconds it takes to perform an operation:

*BEGIN CODE*
    Dim startTime as DateTime
    Dim endTime as DateTime
    Dim ts as TimeSpan

   startTime = DateTime.Now
   DoTheTaskYouAreTiming()
   endTime = DateTime.Now

   ts = endTime.Subtract(startTime)

    MessageBox.Show("Took " & ts.totalMilliseconds & " milliseconds.")
*END CODE*
0
 
prashanth_gurijalaAuthor Commented:
thanx for the info guys,
i got some information from here which can measure in microseconds,
http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q172/3/38.asp&NoWebContent=1

and ticks is not gonna help as its again rounds to milliseconds....

and all system.timers rounds to accuracy of 10 ms

any way thanx for all the infor guys,
prashanth
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now