Jump to content
Sign in to follow this  
tester123

Time & Memory Usage of a Function

Recommended Posts

tester123

Hi All,

I'm trying to calculate the time and memory usage of a particular function in the process. Would like to see if there is a better way or if this is reliable enough. Other threads are specific to memory usage of the entire process, so i'm a lil confused.

Local $mem = ProcessGetStats()
Local $startTime = TimerInit();
ControlClick ( "<<className>>","","CALCULATE"  ) ;Hit the CALCULATE button
Sleep (250) 
Do
    Sleep(250)
Until ControlCommand ("<<className>>", "", "CALCULATE", "isEnabled"); The button is disabled till all the results show up on the screen

Local $endTime = TimerDiff($startTime);Time taken by the function
Local $mem2 = ProcessGetStats()

ConsoleWrite ($endTime)

ConsoleWrite ($mem2[0] - $mem[0]);Diff between the stats retrieved before and after the function was called

Thank You!

Edited by tester123

Share this post


Link to post
Share on other sites
kylomas

tester123,

You are using controlclick so I assume that you are interested in a process other than the one that you are running.  However, the stats you are collecting are for your process.

If you are trying to find out how long it takes to run your function (wall time) then you're timer will give you an approximation of how long (wall time in milliseconds) your function took.

The memory stats are something else.  You are measuring your process's stats, not those of the process whose button you are clicking.  You can specify a process id for processgetstats but I'm not sure what good that will be to you because it is a picture at the moment that the function is run.

There are several threads that deal with performance and process resource usage.  Some of them may have peak usage duing a certain interval.  You can search the forum for them.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
JLogan3o13

Whatever method you choose, I would suggest doing your metrics from a separate script (e.g. don't use the main script to measure the main script). You'll get much more accurate results.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
tester123

Thank you both for your replies! To elaborate a bit on what I'm trying to do - I have a calculator like function which has several inputs. I would like to determine the time taken from the time the user hits "Calculate" till the results show up on the screen and also compute the memory used. I dont have access to the actual function itself which does the computation, so it is just a black-box to me. Since entering all the different inputs could take time, stats of the entire process wouldn't serve the purpose.

@kylomas, Yes, I should probably read up more on memory management from the other threads - i'll update this post if I find something suitable

@JLogan, The reason for not using two scripts is I should trigger the second script when the first script hits the calculate button and stop it when the first scripts shows up the results - Do you still feel that it would give more accurate results in this scenario?

Thank You!!

Edited by tester123

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×