time in

Posted on 2004-11-23
Last Modified: 2012-05-05
I just want to know what is the minimum amount of time difference we can measure by using
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
Question by:prashanth_gurijala
    LVL 28

    Assisted Solution

    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")
    LVL 11

    Assisted Solution

    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
    LVL 11

    Expert Comment

    Now will only return down to the second :(
    LVL 2

    Assisted Solution

    There is the tick, which is 100 nanoseconds
    LVL 2

    Accepted Solution

    Looking over the documentation for the DateTime.Now property, it seems that the resolution depends on the System timer.


    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.


    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:

        Dim startTime as DateTime
        Dim endTime as DateTime
        Dim ts as TimeSpan

       startTime = DateTime.Now
       endTime = DateTime.Now

       ts = endTime.Subtract(startTime)

        MessageBox.Show("Took " & ts.totalMilliseconds & " milliseconds.")
    *END CODE*

    Author Comment

    thanx for the info guys,
    i got some information from here which can measure in microseconds,

    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,

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now