Results 1 to 8 of 8

Thread: Measuring time taken to process block.

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2008
    Posts
    59

    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.

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2008
    Posts
    59

    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?

  4. #4
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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

  5. #5
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    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.

  6. #6
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    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
    Doctor Ed

  7. #7
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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

  8. #8
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: Measuring time taken to process block.

    Quote 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.
    Doctor Ed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width