<?xml version="1.0" encoding="windows-1252"?>
<node id="35320" title="RE: How can I keep track of the execution time of a script?" created="2000-10-04 19:39:49" updated="2005-07-27 07:34:08">
<type id="11">
note</type>
<author id="9135">
Adam</author>
<data>
<field name="doctext">
$^T is the time that the script started. So end your script by returning [time|time()]-$^T. You might want to put this in the sig die handler:
&lt;code&gt;
# your script goes here

BEGIN { $SIG{__DIE__} = sub { print + time() - $^T, $/, @_ } }
print + time() - $^T, $/
&lt;/code&gt;
That prints the run time of your script in seconds.&lt;P&gt;
Update: By the way, there is a module called Benchmark that is great for testing algorithms and routines and such. [Turnstep] wrote a great [tutorials|tutorial] on it called &lt;i&gt;[id://8745]&lt;/i&gt;
&lt;P&gt;&lt;B&gt;Update&lt;/B&gt;: For a variety of reasons, it is much better (and simpler too!) to use a single END block instead of the repition that I suggested. Thanks [merlyn] for pointing this out. (I also like the use of [warn])&lt;P&gt;Also, If your script is taking longer then a minute or two, you might want to break down those seconds to be minutes:seconds, but don't forget the more work you do after that last call to [time], the less accurate the stamp. (Well, time only has a granularity of a second... so you actually have plenty of room, but anyway...)
&lt;code&gt;
END { $a=time-$^T, warn sprintf "Runtime %d min %d sec\n", $a/60, $a%60 }
&lt;/code&gt;</field>
<field name="root_node">
35318</field>
<field name="parent_node">
35318</field>
</data>
</node>
