Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Timing a function 1

Status
Not open for further replies.

MasterRacker

Active member
Joined
Oct 13, 1999
Messages
3,343
Location
US
I found this example of how to time duration, but it requires an add-on library to be installed.
Is there a native way in VBA to time something to the nearest millisecond?

Jeff
[small][purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me[/small]
 
Erm ... VBA or VBScript? They are not the same ...
 
Typo. Meant VBScript. The example is VBS but needs an add-on.

Basically I want o be able to time things in VBS to much better accuracy tan the nearest second.

Jeff
[small][purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me[/small]
 
If I run this poor-person script and look at the data (in unit of ms), I would say native vbs timer can be trusted to within around 15 ms level, again a poor-person deduction.
[tt]
tdelay=1
ti=timer
wscript.sleep tdelay
tf=timer
wscript.echo tdelay & "," & (tf-ti)*1000 & "," & (tf-ti)*1000-tdelay

tdelay=2
ti=timer
wscript.sleep tdelay
tf=timer
wscript.echo tdelay & "," & (tf-ti)*1000 & "," & (tf-ti)*1000-tdelay

for tdelay=10 to 90 step 10
ti=timer
wscript.sleep tdelay
tf=timer
wscript.echo tdelay & "," & (tf-ti)*1000 & "," & (tf-ti)*1000-tdelay
next

for tdelay=100 to 1000 step 100
ti=timer
wscript.sleep tdelay
tf=timer
wscript.echo tdelay & "," & (tf-ti)*1000 & "," & (tf-ti)*1000-tdelay
next

'going back shorter, see if the script now warmed up would change much the behaviour of the handling.

for tdelay=1000 to 100 step -100
ti=timer
wscript.sleep tdelay
tf=timer
wscript.echo tdelay & "," & (tf-ti)*1000 & "," & (tf-ti)*1000-tdelay
next

for tdelay=90 to 10 step -10
ti=timer
wscript.sleep tdelay
tf=timer
wscript.echo tdelay & "," & (tf-ti)*1000 & "," & (tf-ti)*1000-tdelay
next

tdelay=2
ti=timer
wscript.sleep tdelay
tf=timer
wscript.echo tdelay & "," & (tf-ti)*1000 & "," & (tf-ti)*1000-tdelay

tdelay=1
ti=timer
wscript.sleep tdelay
tf=timer
wscript.echo tdelay & "," & (tf-ti)*1000 & "," & (tf-ti)*1000-tdelay
[/tt]
 
> can be trusted to within around 15 ms

Depends on the OS. But yes, XP is typically 15ms

>Is there a native way in [VBScript] to time something to the nearest millisecond?

No, afraid not.
 
Didn't know about the timer function. That should work well enough. (Looks like it'll have to. ;-) )



Jeff
[small][purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top