For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > August 2005 > Script execution time.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Script execution time.
Sara

2005-08-03, 4:59 pm

I have to test/optimize a script on a shared server. The script contains a couple of mySQL queries etc.

Is there a way that I can see the query execution time (like in phymyAdmin) and total script execution time, plus memory & CPU usage? There are a lot of ways doing it in PHP but nothing in PERL/CGI?

I searched CPAN but failed to find my desired requirements. Are there any system commands that can be executed within the script to get these values.

TIA.

Sara.


Chris Devers

2005-08-03, 4:59 pm

On Wed, 3 Aug 2005, Sara wrote:

> I have to test/optimize a script on a shared server. The script
> contains a couple of mySQL queries etc.
>
> Is there a way that I can see the query execution time (like in
> phymyAdmin) and total script execution time, plus memory & CPU usage?
> There are a lot of ways doing it in PHP but nothing in PERL/CGI?
>
> I searched CPAN but failed to find my desired requirements. Are there
> any system commands that can be executed within the script to get
> these values.


Did you not see Benchmark.pm on CPAN then? It should be your first step.

http://search.cpan.org/perldoc?Benchmark

After that, a general search for 'benchmark' may also help.

http://search.cpan.org/search?query=Benchmark&mode=all

That turns up several more possibilities, but Benchmark.pm is the one
you should start with, not least because it is bundled with Perl itself,
so you shouldn't have to install anything extra to run it.


--
Chris Devers
Jay Savage

2005-08-03, 4:59 pm

On 8/3/05, Chris Devers <cdevers@pobox.com> wrote:
> On Wed, 3 Aug 2005, Sara wrote:
>=20
>=20
> Did you not see Benchmark.pm on CPAN then? It should be your first step.
>=20
> http://search.cpan.org/perldoc?Benchmark
>=20
> After that, a general search for 'benchmark' may also help.
>=20
> http://search.cpan.org/search?query...mark&mode=3Dall
>=20
> That turns up several more possibilities, but Benchmark.pm is the one
> you should start with, not least because it is bundled with Perl itself,
> so you shouldn't have to install anything extra to run it.


That depends on what you want to benchmark. Benchmark.pm will
benchmark your script, or parts of your script. It won't, though, help
you benchmark and optimize your MySQL your queries because--assuming
you're not going to hack DBD::MySQL yourself to insert benchmarking
hooks--your benchmarked numbers will include module and connection
overhead.

Actually, this is as it should be: Perl provides ways to access
databases, nothing more. A query doesn't execute differently if it's
called from DBD::MySQL than if it's called from the mysql command line
client. All MySQL sees is "select * from a.a"; it doesn't know whether
than query came from DBD::MySQL, the mysql command line, or a php
script. And it doesn't care. You should come to your perl script with
your SQL already debugged and optimized; debugging one language from
within embedded calls in another is asking for all kinds of trouble.

The best way to benchmark queries is from the command line, or
phpmyAdmin, which is designed for this. You can also use MySQL
Administrator and the Query Browser for this (I think). In any case,
you're looking for an application, not a feature of the programming
language.

HTH,

-- jay
--------------------------------------------------
This email and attachment(s): [ ] blogable; [ x ] ask first; [ ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com http://www.dpguru.com http://www.engatiki.org
Zentara

2005-08-03, 4:59 pm

On Wed, 3 Aug 2005 03:00:01 -0700, sara.samsara@gmail.com (Sara) wrote:

>I have to test/optimize a script on a shared server. The script contains a couple of mySQL queries etc.
>
>Is there a way that I can see the query execution time (like in phymyAdmin) and total script execution time, plus memory & CPU usage? There are a lot of ways doing it in PHP but nothing in PERL/CGI?
>
>I searched CPAN but failed to find my desired requirements. Are there any system commands that can be executed within the script to get these values.
>
>TIA.
>
>Sara.


This should give you the idea.

#!/usr/bin/perl -w
sleep 5;
print "This script took ". (time - $^T) .
" seconds in Perl $] on $^O\n";


If you want to test just subs, get a start time when entering
the sub, and a finish time just before the sub returns. Take the
difference and you should have a pretty good indicator.



--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
Wiggins d'Anconia

2005-08-03, 4:59 pm

zentara wrote:
> On Wed, 3 Aug 2005 03:00:01 -0700, sara.samsara@gmail.com (Sara) wrote:
>
>
>
>
> This should give you the idea.
>
> #!/usr/bin/perl -w
> sleep 5;
> print "This script took ". (time - $^T) .
> " seconds in Perl $] on $^O\n";
>
>
> If you want to test just subs, get a start time when entering
> the sub, and a finish time just before the sub returns. Take the
> difference and you should have a pretty good indicator.
>


Additionally if you are finding the time difference too small you can do
the same but with higher precision using Time::HiRes,

perldoc Time::HiRes

http://danconia.org
Scott R. Godin

2005-08-04, 5:00 pm

Zentara wrote:
> On Wed, 3 Aug 2005 03:00:01 -0700, sara.samsara@gmail.com (Sara) wrote:
>
>
>
>
> This should give you the idea.
>
> #!/usr/bin/perl -w
> sleep 5;
> print "This script took ". (time - $^T) .
> " seconds in Perl $] on $^O\n";
>
>
> If you want to test just subs, get a start time when entering
> the sub, and a finish time just before the sub returns. Take the
> difference and you should have a pretty good indicator.


use Time::Elapse;

#... some code

Time::Elapse->lapse(my $now);

$now = "processing sub foo"
# call your sub here
foo(@args);

print "Time wasted: $now\n";


$ perl -MTime::Elapse -wle 'Time::Elapse->lapse(my $now = "testing 0"); for \
(1..5) {print $now; $now = "testing $_";} print $now;'
00:00:00.000105 [testing 0]
00:00:00.000053 [testing 1]
00:00:00.000035 [testing 2]
00:00:00.000034 [testing 3]
00:00:00.000033 [testing 4]
00:00:00.000035 [testing 5]

:)
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com