Results 1 to 4 of 4

Thread: how long a program runs

  1. #1

    Thread Starter
    Hyperactive Member Art W.'s Avatar
    Join Date
    Apr 2002
    Location
    In My Own Little World, But that’s OK because they know me there!
    Posts
    271

    how long a program runs

    Hello Everyone:

    I would like to know if there is a way to see how long a program runs. I have one that takes a very long time to run, which is not the problem. I start it and go to bed or leave for the day. When I come back it has finished. I do know it takes hours. Is there a way to find out how long it does take to run give or take a couple of minutes?

    Thanks

    Art W
    SLEEP: A Totally Inadequate Substation For Caffeine!

  2. #2
    Lively Member
    Join Date
    Jul 2009
    Location
    Amsterdam, NY
    Posts
    85

    Re: how long a program runs

    im assuming you mean how long it takes a section of code to run correct?

    imports:
    Code:
    imports system.diagnostics
    put this before the code that is taking forever:
    Code:
    Dim sw as new stopwatch
    sw.start()
    at the end of the code put:
    Code:
    sw.stop()
    console.writeline(String.format(The program ran in:  {0}ms, _
                           sw.ElapsedMilliseconds.tostring))
    if you want it to the nearest minute do
    Code:
    dim passedTime as ulong = sw.elapsedMilliseconds mod 60000
    console.writeline(String.format(The program ran in:  {0} minutes, _
                           passedTime.tostring))
    hope this helps!
    CodeBank Posts: Base Converter

  3. #3
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: how long a program runs

    Quote Originally Posted by patplays852 View Post
    im assuming you mean how long it takes a section of code to run correct?

    imports:
    Code:
    imports system.diagnostics
    put this before the code that is taking forever:
    Code:
    Dim sw as new stopwatch
    sw.start()
    at the end of the code put:
    Code:
    sw.stop()
    console.writeline(String.format(The program ran in:  {0}ms, _
                           sw.ElapsedMilliseconds.tostring))
    if you want it to the nearest minute do
    Code:
    dim passedTime as ulong = sw.elapsedMilliseconds mod 60000
    console.writeline(String.format(The program ran in:  {0} minutes, _
                           passedTime.tostring))
    hope this helps!
    He could time the entire execution time of the program, provided that the said program will close itself automatically when done.

    He'd just need to make a new program, use the stop watch you've provided and combine it with the Process class (there's a WaitForExit method). So he'd start the stopwatch, start the program, wait for exit then stop the stopwatch and see how long it took.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  4. #4
    Lively Member
    Join Date
    Jul 2009
    Location
    Amsterdam, NY
    Posts
    85

    Re: how long a program runs

    That is true (I did incorrectly word my statement when i said a section of code), I only really have experience in using this on a button click, I dim it at the start of the sub, then i do my code, and display the time. (which is essentially the "whole" program for what i test.

    If he/she needs help implementing it in his/her project I think we need to see some of the code they have.
    CodeBank Posts: Base Converter

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