Uten Posted January 2, 2007 Share Posted January 2, 2007 (edited) From time to time a thread pops up in the forum to measure the time (or how many iterations can be done in a given time) a block of code takes to execute. most solutions use TimeInit and TimeDiff to do the measures. This is not a accurate way to measure the time spent by the code block. The reason is that TimeDiff measure the time spent by all processes on the system and not just the one we want to measure. So, a better approach in AutoIt is to use GetProcessTimes in kernel32.dll. I have created two udfs to resemble TimerInit and TimerDiff. They are called ProfileInit and ProfileDiff. They operate on the running process. ProfileDiff will return an array containing the time in 100 nanoseconds intervals since ProfileInit was called. Usage: Local $foo Local $i, $j, $k Local $time, $ts, $pi[1] $pi = ProfileInit() ;ArrayDump($pi, "Profile Inint:") $ts = Timerinit() For $i = 0 to 3 For $j = 1 to 100000 $k += Random(-5, 5, 1) next Local $pd = ProfileDiff($pi) $time = TimerDiff($ts) ;K=kernel-time, U=User-time spendt by the process identified by @AutoItPID ;Dividing by 10000 to get ms ConsoleWrite(StringFormat( "SUM:=%d\tT:%.6d, K:%d, U:%d, K+U:%d ms", $k, $time, $pd[1], $pd[2], Round(($pd[1]+$pd[2])/10000, 0)) & @LF) $k = 0 next $Process = 0oÝ÷ Ù Enjoy, Uten.. EDIT: Forgot some globals. Edited January 2, 2007 by Uten mLipok 1 Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 3, 2007 Moderators Share Posted January 3, 2007 (edited) SUM:=1267 T:001021, K:0, U:9531250, K+U:953 msSUM:=-766 T:002043, K:0, U:19531250, K+U:1953 msSUM:=1673 T:003046, K:0, U:29218750, K+U:2922 msSUM:=-293 T:004058, K:0, U:39218750, K+U:3922 msWindows XP Pro SP2AMD Athlon 643700+2.40 GHz, 2.00 GB of RAMEdit:Killed 2 processes and then got this:SUM:=-729 T:001011, K:0, U:9687500, K+U:969 msSUM:=-1555 T:001982, K:0, U:18906250, K+U:1891 msSUM:=278 T:002933, K:0, U:28125000, K+U:2813 msSUM:=1171 T:003916, K:0, U:37343750, K+U:3734 msSUM:=-324 T:000986, K:0, U:9375000, K+U:938 msSUM:=-425 T:001968, K:0, U:19062500, K+U:1906 msSUM:=387 T:002949, K:0, U:28593750, K+U:2859 msSUM:=-638 T:003915, K:0, U:37968750, K+U:3797 ms(Ran it twice)Edit2:Probably as fast as I'm going to get it:SUM:=-11 T:000928, K:0, U:9375000, K+U:938 msSUM:=2029 T:001836, K:156250, U:18281250, K+U:1844 msSUM:=582 T:002730, K:156250, U:27187500, K+U:2734 msSUM:=-903 T:003795, K:156250, U:36093750, K+U:3625 ms Edited January 3, 2007 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
llamnuds Posted January 3, 2007 Share Posted January 3, 2007 I'm a noob at AutoIt, but when I get more into it, I think this'll be really handy. Thanks, llamnuds Link to comment Share on other sites More sharing options...
Uten Posted January 5, 2007 Author Share Posted January 5, 2007 Outch, why don't I get mail notifications from this thread? Nice to know you have tested it a bit @SmOke_N. Maybe it can help you out when you try to improve your EnCodeIt code. I know you constantly improve that nice application of yours. Hope you to can benefit from it to @llamnuds. Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling Link to comment Share on other sites More sharing options...
clearguy Posted January 22, 2007 Share Posted January 22, 2007 Please can you explain what SUM,T,K and U means? I've never met anyone who codes binary. StringMultiInsert()SOW EncryptFrench autoit forum - forum français Link to comment Share on other sites More sharing options...
Uten Posted January 23, 2007 Author Share Posted January 23, 2007 Sorry about the late reply. Still don't get mail notification. Must be something with my forum settings. You sort of find it in this line: ConsoleWrite(StringFormat( "SUM:=%d\tT:%.6d, K:%d, U:%d, K+U:%d ms", $k, $time, $pd[1], $pd[2], Round(($pd[1]+$pd[2])/10000, 0)) & @LF) So, SUM The sum of my sample calculation. T: Time as measured with TimerInit and TimerDiff K: CPU time spent by then kernel. U: CPU time spent in user code. K+U: Total time spent by the process. This time should be compared with T: Especially on a computer running many processes. Hope that explains it.. Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now