[Mastering-perl] Profiling

Florian Merges fmerges at cpan.org
Sat Oct 7 14:19:04 EDT 2006


Hi,

First of all I would tell this usual stuff about profiling and
improving/optimizing code...

I think the section about Devel::DProf should be right below the SmallProof.

You mention Devel::Cover, but what about Pod::Coverage et al??


The general approach
----------------------------

I want to track with queries   -> which queries

Profiling DBI
---------------

Why so?

foreach my $name (
    qw(One Two Three Four Five Six Seven Eight Nine Ten),
    qw(Eleven Twelve Thirteen Fourteen Fifteen Sixteen Seventeen Eighteen
        Nineteen)
    )

Think it would be cleaner to use a array variable, or using one 'qw'...


to see where I can approve it  -> improve it

REmember that this is -> Remember

On the second example you use these array way:

my @array = ( qw( Zero ),
    qw(One Two Three Four Five Six Seven Eight Nine Ten),
    qw(Eleven Twelve Thirteen Fourteen Fifteen Sixteen Seventeen Eighteen
        Nineteen)
    );

But again, why these 3 qw calls? why not:

my @array = qw(
...
);

Another thing... this kind of sentence:

my( $sth ) = $self->simple_query( <<"SQL", $country );
...
my( $hundreds ) = $array[ $digit ];

This my calls, isn't it more clean to remove those (), where not necessary?


Making it even easier
---------------------------

in a file isntead of  -->  instead

A footnote to where you can find more info about SQLite could be useful (I
know people knows it on www.sqlite.org).


Writing my own profiler
-----------------------------

Fixed code...

END {
    print "\nLine summary for $0\n\n";

    open FILE, $0 or die "Could not open $0\n$!";

    my $count = 0;
    while (<FILE>) {
        my $num = $counter[++$count] || 0;
        if (defined $_) {
            printf "%6d %s", $num, $_;
        }
    }
};




Regards,

Florian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://five.pairlist.net/pipermail/mastering-perl/attachments/20061007/174df139/attachment.htm


More information about the Mastering-perl mailing list