|
-
Sep 10th, 2008, 02:19 AM
#1
Thread Starter
Member
Measuring time taken to process block.
Is there anyway to measure the time it takes for a block of code to be executed?
Just want to measure if my optimisations are really optimising.
-
Sep 10th, 2008, 03:08 AM
#2
Re: Measuring time taken to process block.
yes
you can use a timer object to accomplish what you want...
do a search in the forum for timer and you will get dearth of posts
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Sep 10th, 2008, 03:45 AM
#3
Thread Starter
Member
Re: Measuring time taken to process block.
I attempted to use a timer by setting the interval to "1" then inside the timer having it increase a variable bTime by 1.
At the start of the block I'd enable the timer then disable it at the end and bTime hadn't increased at all.
So I assumed this meant that the timer didn't run its interval if a block of code is half way through being executed - or does this just mean the code is executed so quickly that 1/1000th of a second hasn't passed?
-
Sep 10th, 2008, 04:01 AM
#4
Re: Measuring time taken to process block.
1) Set the interval to 1000
2) What are you trying to do?
3) How are you measuring the time taken for the sub to be complete?
Also there is one more way of doing it without using timers for example
Code:
Sub TestTime()
Dim StartTime, EndTime
Dim Count
StartTime = Now
'#######SAMPLE CODE##########
Count = 0
For i = 1 To 1000
For j = 1 To 100000
Count = Count + 1
Next j
Next
'############################
EndTime = Now
MsgBox "Start Time: " & Format(StartTime, "hh:mm:ss") & ", End Time: " & _
Format(EndTime, "hh:mm:ss")
End Sub
Last edited by Siddharth Rout; Sep 10th, 2008 at 04:14 AM.
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Sep 10th, 2008, 02:47 PM
#5
Re: Measuring time taken to process block.
You can also use a profiling tool. VB Watch is free to run on projects of <= 10 source files.
-
Sep 10th, 2008, 03:13 PM
#6
Re: Measuring time taken to process block.
A modification of Koolsid's code:
Code:
Private Sub Command1_Click()
Dim StartTime As Double
StartTime = Now
'#######SAMPLE CODE##########
For i = 1 To 2000
For j = 1 To 100000
Next
Next
'############################
MsgBox "Elapsed Time: " & Format(Now - StartTime, "hh:mm:ss")
' Accurate to the nearest second
End Sub
-
Sep 10th, 2008, 03:16 PM
#7
Re: Measuring time taken to process block.
Code Doc: Cheers
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Sep 10th, 2008, 04:11 PM
#8
Re: Measuring time taken to process block.
 Originally Posted by koolsid
Code Doc: Cheers 
Thanks, Koolsid. I actually use this in all my tutorial software when tracking the elapsed time that a user takes to complete a Q&A tutorial. These can sometimes go on for hours or could be as short as a few minutes. The accuracy to the nearest second is usually sufficient.
I also run a timer in the background to show a countdown of time remaining from an allotted time, which is a bit tricky. Regardless, I always capture the start time when the form loads and record (or add to) the elapsed time when the form unloads. I then store that value as a single on a random access file.
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
|