niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » Perl
FAQ 3.6 How do I profile my Perl programs?
Post new topic   Reply to topic Page 1 of 1 [1 Post] View previous topic :: View next topic
Author Message
PerlFAQ Server
*nix forums Guru


Joined: 09 Apr 2005
Posts: 1008

PostPosted: Tue Jul 18, 2006 7:03 pm    Post subject: FAQ 3.6 How do I profile my Perl programs? Reply with quote

This is an excerpt from the latest version perlfaq3.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .

--------------------------------------------------------------------

3.6: How do I profile my Perl programs?

You should get the Devel::DProf module from the standard distribution
(or separately on CPAN) and also use Benchmark.pm from the standard
distribution. The Benchmark module lets you time specific portions of
your code, while Devel::DProf gives detailed breakdowns of where your
code spends its time.

Here's a sample use of Benchmark:

use Benchmark;

@junk = `cat /etc/motd`;
$count = 10_000;

timethese($count, {
'map' => sub { my @a = @junk;
map { s/a/b/ } @a;
return @a },
'for' => sub { my @a = @junk;
for (@a) { s/a/b/ };
return @a },
});

This is what it prints (on one machine--your results will be dependent
on your hardware, operating system, and the load on your machine):

Benchmark: timing 10000 iterations of for, map...
for: 4 secs ( 3.97 usr 0.01 sys = 3.98 cpu)
map: 6 secs ( 4.97 usr 0.00 sys = 4.97 cpu)

Be aware that a good benchmark is very hard to write. It only tests the
data you give it and proves little about the differing complexities of
contrasting algorithms.



--------------------------------------------------------------------

The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.

If you'd like to help maintain the perlfaq, see the details in
perlfaq.pod.

--
Posted via a free Usenet account from http://www.teranews.com
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [1 Post] View previous topic :: View next topic
The time now is Thu Jan 08, 2009 6:48 am | All times are GMT
navigation Forum index » Programming » Perl
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Need Help with Program in Perl on a Netware Server fhadzocos@gmail.com Perl 3 Fri Jul 21, 2006 1:57 pm
No new posts problems using oddmuse with mod_perl2 inside apache2.2 pe... Fergus McMenemie Perl 0 Fri Jul 21, 2006 9:48 am
No new posts Problem with Win32-SerialPort over bluetooth @ windows + ... ctloh Perl 0 Fri Jul 21, 2006 8:08 am
No new posts Posting Guidelines for comp.lang.perl.misc (: 1.... Tad McClellan Perl 0 Fri Jul 21, 2006 7:22 am
No new posts Perl Help - easy one Marc Perkel Exim 2 Fri Jul 21, 2006 5:54 am

Web Advertising | Credit Card Consolidation | Hackers | Personal Car Finance | MPAA
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.6129s ][ Queries: 16 (0.4129s) ][ GZIP on - Debug on ]