Timer too accurate

Status
Not open for further replies.

yxz152830

Active Member
Joined
Oct 6, 2021
Messages
393
Office Version
  1. 365
Platform
  1. Windows
Gurus,
I was trying out different time functions. I wanted to record the run time of a code. My concern is that the result is too accurate? or say fake. doesnt runtime of the subroutine itself also cost a tiny bit of time and make records something like 30.0xxx? Please check below code and result

VBA Code:
Sub pop2()
For x = 1 To 10
st = Timer
d = st + 3
For Each cell In Range(Cells(18, 1), Cells(18, 10))
Do
Loop Until d <= Timer
d = Timer + 3
cell.Interior.ColorIndex = 3
Next cell
st = Timer - st
Range("o100").End(xlUp).Offset(1, 0) = st
Range(Cells(18, 1), Cells(18, 10)).Clear
Next x
End Sub

timer
30.000​
30.000​
30.000​
30.000​
30.000​
30.000​
30.000​
30.000​
30.000​
30.000​
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
You are doing very little work (changing colour of 10 cells) so of course the time taken is tiny.
There are more precise timers using the Windows API, but a much simpler approach is to make your loops much bigger, eg change the colour of 10,000 cells instead of 10.
Then you can take that time and divide by 1000 to get the average for 10 cells pretty precisely
If that's not accurate enough, recolour 100,000 cells and divide the time by 10,000....
 
Upvote 0
STOP posting the same question multiple times. Per Forum Rules (#12), posts of a duplicate nature will be locked or deleted.

Thread closed.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,214,965
Messages
6,122,500
Members
449,090
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top