Timer which counting smaller than 1 second intervals

B

Berend Botje

Hi,

I'm looking for a way to use a counter which can count smalle
intervals than the standard 1 second. I need something like 0.
seconds.

Currently I'm using this as my pause module. Problem is, it uses 100
of my CPU, which is (naturally) unacceptable.

Public Sub Pause(Pausetime As Single)

Dim Starttime As Single

Starttime = Timer

Do Until Timer > Starttime + Pausetime
Loop

End Sub

In this sub "Pausetime" is used to determine the pause interval. In m
case 0.1 seconds (pausetime = 0.1)

Any suggestions are welcome.

Regards,

Berend Botj
 
K

keepITcool

Rob,

i see a subsecond wait (a plain api sleep)
but i dont see a subsecond delay

--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Rob van Gelder wrote :
 
K

keepITcool

I did find some code with a timer in
SpeedTestRangeRead.

I disagree with your test method...

I've changed the 3rd test...

With .Range("A1")
For i = 0 To 10000 - 1
lngTemp = .Offset(i, 0).Value
Next
End With


Test 1: 85
Test 2: 178
Test 3: 74 (original test 3: 151)

Offset wins handsdown if used properly..
your original lngTemp = rng.Offset(i, 0).Value
has to reevaluate the range object in every iteration.

<VBG>



--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Rob van Gelder wrote :
 
R

Rob van Gelder

Thanks for the comment and feedback.
Perhaps you're right. I hardly understand the inner workings of how VB/Excel
evaluates ranges.

The code purpose was more to demonstrate speed test possibilities than prove
or disprove certain methods of reading - even though that is exactly what
it's doing.

I had planned to develop it into a rough profiler application but soon
realised what was involved - especially handling exit do, exit sub, exit,
exit function, etc...


Back to the 3rd test...
I get no significant difference between the two tests.


Declare Function timeGetTime Lib "winmm.dll" () As Long

Dim lngStart As Long

Sub Start()
lngStart = timeGetTime()
End Sub

Function Finish()
Finish = timeGetTime() - lngStart
End Function

Sub test()
Const cQuant = 65536
Dim i As Long, lngTemp As Long, rng As Range

With ActiveSheet
'set up test data
For i = 1 To cQuant: .Cells(i, 1).Value = i: Next

Start
Set rng = .Range("A1")
For i = 0 To cQuant - 1
lngTemp = rng.Offset(i, 0).Value
Next
Debug.Print "Test 3: " & Finish

Start
With .Range("A1")
For i = 0 To cQuant - 1
lngTemp = .Offset(i, 0).Value
Next
End With
Debug.Print "Test 4: " & Finish
End With
End Sub


Test 3: 500
Test 4: 485


Cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top