http://www.perlmonks.org?node_id=1037763

taint has asked for the wisdom of the Perl Monks concerning the following question:

Greetings everyone,

I thought I knew exactly how to accomplish this task. But apparently I don't.
I tried to add a timer that would measure the time it took Perl to produce (process) rendering any of my web pages -- not how long the Client (browser) took to load the page, or the server to send it.

Because Perl is so great, and because my functions, and subs are so effecient; I chose Time::HiRes, knowing we'd be talking milliseconds. Here's what I'm using:

#!/usr/bin/perl -Tw # heavily commented for the sake of this post # presents time in my chosen format use POSIX qw/strftime/; # used for the Perl page rendered time I'm trying to produce use Time::HiRes qw/gettimeofday tv_interval/; # trickery to send the page as application/xhtml+xml, # if the client supports it if ($ENV{'HTTP_ACCEPT'} =~ /application\/xhtml\+xml/) { print "content-type:application/xhtml+xml; charset=utf-8\n\n"; } else { print "content-type:text/html; charset=utf-8\n\n"; } # here's where I start my timer my $start_time = [gettimeofday]; # just to add some of my local routines to my @INC use lib './localincs/'; # again, my preferred time format (has nothing to do with my timer) my $utc_time = strftime('%F %T %z',localtime); ...yadda,yadda,yadda... # bottom of web page, just before </body></html> my $total_time = tv_interval($start_time); # the following line should present something like this: # Page processed by Perl <my Perl version number> in 0.00001 seconds # But only produces the Perl version number printf('Page processed by Perl %s in %.02f seconds',$],$total_time);
Can anyone see why the "elapsed/process time" isn't being produced?
Currently, it shows up as
in 0.00 seconds



Thanks for taking the time.

--chris

#!/usr/bin/perl -Tw
use perl::always;
my $perl_version = "5.12.4";
print $perl_version;