Results 1 to 20 of 20

Thread: Nanosecond

  1. #1

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Resolved Nanosecond

    is there any method to trap an event if occuring in nanosecond .
    if not atleast
    1/10000 of second...?
    i think timer is not good option for dealing lower than 1/1000 of second..!
    Last edited by vbPoet; Feb 24th, 2005 at 04:42 PM.

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Nanosecond

    The GetTickCount API is the lowest increment of time that you can use in VB.
    Here is an example.

    VB Code:
    1. 'In general section
    2. Private Declare Function GetTickCount& Lib "kernel32" ()
    3. Private Sub Form_Load()
    4.     'KPD-Team 1998
    5.     'URL: [url]http://www.allapi.net/[/url]
    6.     'E-Mail: [email][email protected][/email]
    7.     'Get the tickcount
    8.     ret& = GetTickCount&
    9.     MsgBox Str$(ret& / 60000) + " minutes."
    10. End Sub

  3. #3

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: Nanosecond

    ret1& = GetTickCount&
    ret2& = GetTickCount&
    MsgBox Str$(ret1& - ret2& )
    ---------------------------------
    it always displays ZERO 0
    but i want to get the differnece it elapsed during executing first line to second.
    .....!!!!
    i know it will be difficult
    but i know nothing is impossible.. :mike:
    Last edited by vbPoet; Feb 24th, 2005 at 01:54 PM.

  4. #4
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Nanosecond

    Quote Originally Posted by vbPoet
    ret1& = GetTickCount&
    ret2& = GetTickCount&
    MsgBox Str$(ret1& - ret2& )
    ---------------------------------
    it always displays ZERO 0
    but i want to get the differnece it elapsed during executing first line to second.
    .....!!!!
    i know it will be difficult
    but i know nothing is impossible.. :mike:
    VB Code:
    1. Private Declare Function GetTickCount& Lib "kernel32" ()

    did you add that to the top of your form?

  5. #5

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669
    Yeah ..

  6. #6
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Nanosecond

    Quote Originally Posted by vbPoet
    ret1& = GetTickCount&
    ret2& = GetTickCount&
    MsgBox Str$(ret1& - ret2& )
    ---------------------------------
    it always displays ZERO 0
    but i want to get the differnece it elapsed during executing first line to second.
    .....!!!!
    i know it will be difficult
    but i know nothing is impossible.. :mike:
    The reason this is happening is because it is the same the time in the first line as it is in the second.

    Its milliseconds i dont think you can get much more accurate than that in vb.

    Whats the purpose of doing this?

    Pino

  7. #7

  8. #8
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913

    Re: Nanosecond

    Quote Originally Posted by Pino
    The reason this is happening is because it is the same the time in the first line as it is in the second.

    Its milliseconds i dont think you can get much more accurate than that in vb.

    Whats the purpose of doing this?

    Pino

    You can actually get down to .10 of a millisecond using some API called QueryPerformace or something like that.

    GetTickCount only updates like every 15 milliseconds or something like that.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  9. #9
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Nanosecond

    Quote Originally Posted by Cander
    You can actually get down to .10 of a millisecond using some API called QueryPerformace or something like that.

    GetTickCount only updates like every 15 milliseconds or something like that.
    Yes i use the query performance counter in most of my apps but i didnt know that :-/

    Interesting thanks

  10. #10
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Nanosecond

    Wow. I don't think i've even heard of that. I'll have to keep it in my bag of tricks.

    Start Value: 95052324.5422
    End Value: 95052324.5444
    QueryPerformanceCounter minimum resolution: 1/3579545 sec
    API Overhead: 6.14603252648032E-06 seconds

    GetTickCount minimum resolution: 10 ms
    Took 22963 loops

    timeGetTime minimum resolution: 1 ms
    Took 4467 loops


    Isn't that still 1 ms? Still better than GetTickCount, though!
    Last edited by dglienna; Feb 24th, 2005 at 03:12 PM.

  11. #11
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913

    Re: Nanosecond

    Isn't that still 1 ms? Still better than GetTickCount, though!
    Well whatever route you take you are going to have a problem with consistancy since you are going through different layers to get that data and other processes and factors can affect your numbers at such high precission. The most accurate would be to measure and time CPU cycles which goes way beyond the scope of VB.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  12. #12

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: Nanosecond

    i m again confused with ...
    how can i get ... time difference b/w two statements.
    -------------
    it is taking LARGE INTEGER ...
    highpart
    lowpart
    but what is the real formula to conclude the result..
    thx in advance for guiding me..!

  13. #13
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Nanosecond

    Quote Originally Posted by szlamany
    Did you see Joacim's post to another thread you have - I think he's banging his head right now too.
    Not really... I just stopped careing

  14. #14
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Nanosecond

    As Martin's link shows the most effeciant timers are multimedia timers. However they rely on your hardware (if your hardware have any MM timers at all, which all modern computers have). But you can never rely on that they will have the same high resolution on different computers. But the calls will never be slower then around 10ms which is the same resolution used by GetTickCount.

    The reason the difference between two calls to GetTickCount is zero is of course because the two calls was made faster then about 10ms.

  15. #15

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: Nanosecond

    i m really trying to keep in touch with all of you guys..
    because when someone asks question he is presumed to be student and other one is teacher
    i respect my teachers.
    i don't where m i creating problems for my teachers.
    if you look into my profile my 40% threads are solved and i have marked it as nike sign...
    -----------------
    why i need it...?
    i need it because of various reasons..
    i) to check to what extent VB is accurate or reach at
    ii) i m going to work on hardware interfacing project,my this knowledge will work
    to choose what is better for me VB or VC
    iii) it is always good to have deep knowledge..
    -----
    and many other reasons can be applied .....!!! :mike:

  16. #16
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Nanosecond

    GetTickCount minimum resolution: 10 ms
    Took 22963 loops

    timeGetTime minimum resolution: 1 ms
    Took 4467 loops

    Isn't that faster ?

  17. #17

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: Nanosecond

    VB Code:
    1. If QueryPerformanceCounter(Ctr1) Then
    2.           QueryPerformanceCounter Ctr2
    3.           Debug.Print "Start Value: "; Format$(Ctr1, "0.0000")
    4.           Debug.Print "End Value: "; Format$(Ctr2, "0.0000")
    5.           QueryPerformanceFrequency Freq
    6.           Debug.Print "QueryPerformanceCounter minimum resolution: 1/" & _
    7.                       Freq * 10000; " sec"
    8.           Debug.Print "API Overhead: "; (Ctr2 - Ctr1) / Freq; "seconds"
    9.         Else
    10.           Debug.Print "High-resolution counter not supported."
    11.         End If
    solved....
    thx for taking part

  18. #18
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Nanosecond

    Start Value: 95052324.5422
    End Value: 95052324.5444
    QueryPerformanceCounter minimum resolution: 1/3579545 sec
    API Overhead: 6.14603252648032E-06 seconds

    GetTickCount minimum resolution: 10 ms
    Took 22963 loops

    timeGetTime minimum resolution: 1 ms
    Took 4467 loops


    Isn't that still 1 ms? Still better than GetTickCount, though!
    There are actually 3 timers being compared here:
    GetTickCount minimum resolution: 10 ms
    timeGetTime minimum resolution: 1 ms
    and
    QueryPerformanceCounter minimum resolution: .0003 ms

    that's 300 nanoseconds

  19. #19
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Nanosecond

    Oh, OK Now I understand. That is a lot faster. Not just a little!

  20. #20
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Nanosecond

    Did anyone notice that he is subtracting the end time from the start time which won't do him any good (besides not having GetTickCount not defined properly).
    ret1& = GetTickCount&
    ret2& = GetTickCount&
    MsgBox Str$(ret1& - ret2& )
    Should Be

    MsgBox ret2& - ret1&

    I know, I know, Silly details...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width