|
-
Feb 23rd, 2005, 04:45 PM
#1
Thread Starter
Fanatic Member
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.
-
Feb 23rd, 2005, 05:01 PM
#2
Re: Nanosecond
The GetTickCount API is the lowest increment of time that you can use in VB.
Here is an example.
VB Code:
'In general section
Private Declare Function GetTickCount& Lib "kernel32" ()
Private Sub Form_Load()
'KPD-Team 1998
'URL: [url]http://www.allapi.net/[/url]
'Get the tickcount
ret& = GetTickCount&
MsgBox Str$(ret& / 60000) + " minutes."
End Sub
-
Feb 24th, 2005, 01:39 PM
#3
Thread Starter
Fanatic Member
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.
-
Feb 24th, 2005, 02:00 PM
#4
Re: Nanosecond
 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:
Private Declare Function GetTickCount& Lib "kernel32" ()
did you add that to the top of your form?
-
Feb 24th, 2005, 02:36 PM
#5
Thread Starter
Fanatic Member
-
Feb 24th, 2005, 02:52 PM
#6
Re: Nanosecond
 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
-
Feb 24th, 2005, 02:55 PM
#7
Re: Nanosecond
 Originally Posted by dglienna
The GetTickCount API is the lowest increment of time that you can use in VB]
Not necessarily.
-
Feb 24th, 2005, 02:55 PM
#8
Re: Nanosecond
 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.
-
Feb 24th, 2005, 02:57 PM
#9
Re: Nanosecond
 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
-
Feb 24th, 2005, 03:06 PM
#10
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.
-
Feb 24th, 2005, 03:17 PM
#11
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.
-
Feb 24th, 2005, 03:23 PM
#12
Thread Starter
Fanatic Member
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..!
-
Feb 24th, 2005, 03:26 PM
#13
Re: Nanosecond
 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
-
Feb 24th, 2005, 03:35 PM
#14
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.
-
Feb 24th, 2005, 03:40 PM
#15
Thread Starter
Fanatic Member
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:
-
Feb 24th, 2005, 04:07 PM
#16
Re: Nanosecond
GetTickCount minimum resolution: 10 ms
Took 22963 loops
timeGetTime minimum resolution: 1 ms
Took 4467 loops
Isn't that faster ?
-
Feb 24th, 2005, 04:31 PM
#17
Thread Starter
Fanatic Member
Re: Nanosecond
VB Code:
If QueryPerformanceCounter(Ctr1) Then
QueryPerformanceCounter Ctr2
Debug.Print "Start Value: "; Format$(Ctr1, "0.0000")
Debug.Print "End Value: "; Format$(Ctr2, "0.0000")
QueryPerformanceFrequency Freq
Debug.Print "QueryPerformanceCounter minimum resolution: 1/" & _
Freq * 10000; " sec"
Debug.Print "API Overhead: "; (Ctr2 - Ctr1) / Freq; "seconds"
Else
Debug.Print "High-resolution counter not supported."
End If
solved....
thx for taking part
-
Feb 24th, 2005, 04:56 PM
#18
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
-
Feb 24th, 2005, 05:52 PM
#19
Re: Nanosecond
Oh, OK Now I understand. That is a lot faster. Not just a little!
-
Sep 15th, 2005, 01:05 PM
#20
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|