|
-
Jul 22nd, 2010, 02:29 PM
#1
Thread Starter
Hyperactive Member
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!
-
Jul 22nd, 2010, 02:39 PM
#2
Lively Member
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!
-
Jul 22nd, 2010, 03:06 PM
#3
Re: how long a program runs
 Originally Posted by patplays852
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.
-
Jul 22nd, 2010, 03:11 PM
#4
Lively Member
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.
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
|