Re: the time a program runs



On Mon, 2005-09-26 at 06:32 -0400, Tom Allison wrote:
> Octavian Rasnita wrote:
> > Hi,
> >
> > I have tried to find out the time a perl program runs, and I have used:
> >
> > #at the start of the program:
> > my $begin = (times)[0];
> > my $begin_t = time();
> >
> > ... The program follows
> >
> > # at the end of the program:
> > my $end = (times)[0] - $begin;
> > my $end_t = time() - $begin_t;
> > print "end: $end\nEnd_t: $end_t\n";
> >
> > After running the program, it prints:
> >
> > end: 4.953
> > End_t: 19
> >
> > Why does this difference appear?
> >
> >
> > The program is a very short one, for testing the speed of Storable module.
> >
>
> Try this:
>
> The global var $^T stores the time of execution start.
> So at the end you want:
>
> print (time() - $^T) , " seconds to complete\n";
>
> However, if you want more accuracy then you might consider Time::HiRes
> or better yet Benchmark. Benchmark is a very useful tool.
>
Hi,

If you are on a *nix system you can do:
time ./my-script.pl
and you get:
real 0m3.562s
user 0m2.201s
sys 0m0.017s

What is the advantage of using something in the perl script (Time::HiRes
|| the $^T) ?

Thanks.

Dan.


--

.



Relevant Pages

  • Re: heres a challenge =)
    ... > Bruce Barnett wrote: ... >> Benchmark it against my perl program too, ... Sending unsolicited commercial e-mail to this account incurs a fee of ...
    (comp.unix.shell)
  • Re: heres a challenge =)
    ... >>against a gui tool that doees the same thing... ... > Benchmark it against my perl program too, ...
    (comp.unix.shell)
  • Re: heres a challenge =)
    ... >>Bruce Barnett wrote: ... >>>Benchmark it against my perl program too, ... So you should at least use binmodeon the filehandle. ...
    (comp.unix.shell)
  • Re: Time::HiRes module and timing a command...
    ... > I want to write a small perl program to test the performance of ... Use the 'Benchmark' module. ... It's comes standard with Perl. ... (Friedrich Nietzsche) ...
    (comp.lang.perl.misc)