Perl/Timing: Difference between revisions
From charlesreid1
(Created page with "While a profiler gives you a much more detailed picture of where time is spent in the code, sometimes you're just after an overall execution time or wall time for a single sni...") |
No edit summary |
||
| Line 16: | Line 16: | ||
[[Category:Profiling]] | [[Category:Profiling]] | ||
[[Category:Perl]] | |||
[[Category:Timing]] | |||
[[Category:Programming]] | |||
Latest revision as of 02:19, 20 March 2017
While a profiler gives you a much more detailed picture of where time is spent in the code, sometimes you're just after an overall execution time or wall time for a single snippet. In that case, you can use Perl's built-in time function (which gives second-level granularity) or you can go for the High Resolution time library HiRes:
http://search.cpan.org/~jhi/Time-HiRes-1.9741/HiRes.pm
This is a drop-in replacement for time. So your Perl file just needs this:
#!/usr/bin/perl use Time::HiRes qw(time); my $start = time; doit(); my $duration = time - $start; printf "Execution time: %0.3f s \n",$duration;