Ask a Question related to PERL Beginners, Design and Development.
-
Stuart Clemons #1
How to calculate elapsed time ?
Hi all:
I'm trying to determine how long an system operation takes. Anyone know
of a simple way to do this ?
I wanted to establish the start time. Then run the operation. Then mark
the finish time. Then substract the start time from the finish time to
get an elapsed time. Here's the simplistic approach I tried. I'm sure I
need a time that is measured in seconds or something like that, but I'm
not sure how to do this.
TIA
Here's what I tried:
#!/usr/bin/perl -w
use warnings;
use strict;
my $start = "Tue Jan 27 15:40:16 2004";
print "This is the start time: $start \n";
system (This is where the system process stuff goes);
my $finish = localtime;
print "This is the finish time: $finish \n";
my $elapsedtime = ("$finish" - "$start") ;
print "This is the time diff: $elapsedtime \n";
The above obviously didn't work. Here's what it returned:
This is the start time: Tue Jan 27 15:40:16 2004
Argument "Tue Jan 27 15:40:16 2004" isn't numeric in subtraction (-) at
C:\Perl\timetest.pl line 13.
This is the finish time: Tue Jan 27 19:45:56 2004
This is the time diff: 0
Argument "Tue Jan 27 19:45:56 2004" isn't numeric in subtraction (-) at
C:\Perl\timetest.pl line ClearCase\Us
Stuart Clemons Guest
-
Time elapsed record
Running FM 5.5 on PC. Is there a way to show elapsed times for each record in table view. I want to show how long a patient has been admitted to... -
Elapsed time record help.
Running FM 5.5 on PC. Is there a way to show elapsed times for each record in table view. I want to show how long a patient has been admitted to... -
Calculate elapsed time in minutes
Try: DateDiff("n",,) Your code has you comparing TaskStart to TaskStart and then dividing the result (which is in minutes from the 'n'... -
Calculate Time
I have a form that shows the Employees loginTime and logoffTime with a medium time format. The Employee clocks in and then out. I need to... -
calculate the time
Personal, necessary to do a select that contains for NAME, if the name has more than a connection I want to catch the total time of those... -
James Edward Gray II #2
Re: How to calculate elapsed time ?
On Jan 27, 2004, at 6:50 PM, [email]stuart_clemons@us.ibm.com[/email] wrote:
Howdy.> Hi all:
You were on the right track. Try this:> I'm trying to determine how long an system operation takes. Anyone
> know
> of a simple way to do this ?
my $start = time;
# do something to time here
my $time_taken = time - $start;
If you want more information on the time() subroutine, try (at the
commandline):
perldoc -f time
And if you get into timing things it won't be long before you want the
Benchmarking module, generally. You can read about it too:
perldoc Benchmark
Hope that helps.
James
James Edward Gray II Guest
-
Randy W. Sims #3
Re: How to calculate elapsed time ?
On 1/27/2004 7:50 PM, [email]stuart_clemons@us.ibm.com[/email] wrote:
Use the Benchmark module or Time::Hires.> Hi all:
>
> I'm trying to determine how long an system operation takes. Anyone know
> of a simple way to do this ?
>
> I wanted to establish the start time. Then run the operation. Then mark
> the finish time. Then substract the start time from the finish time to
> get an elapsed time. Here's the simplistic approach I tried. I'm sure I
> need a time that is measured in seconds or something like that, but I'm
> not sure how to do this.
Randy.
Randy W. Sims Guest
-
Toby Stuart #4
RE: How to calculate elapsed time ?
[code snipped]> -----Original Message-----
> From: [email]stuart_clemons@us.ibm.com[/email] [mailto:stuart_clemons@us.ibm.com]
> Sent: Wednesday, January 28, 2004 11:51 AM
> To: [email]beginners@perl.org[/email]
> Subject: How to calculate elapsed time ?
>
>
> Hi all:
>
> I'm trying to determine how long an system operation takes.
> Anyone know
> of a simple way to do this ?
>
> I wanted to establish the start time. Then run the
> operation. Then mark
> the finish time. Then substract the start time from the
> finish time to
> get an elapsed time. Here's the simplistic approach I tried.
> I'm sure I
> need a time that is measured in seconds or something like
> that, but I'm
> not sure how to do this.
>
> TIA
>use Time::Elapse;>
# somewhere in your program...
Time::Elapse->lapse(my $now);
#...rest of program execution
print "Time Wasted: $now\n";
Toby Stuart Guest
-
Wiggins D'Anconia #5
Re: How to calculate elapsed time ?
[email]stuart_clemons@us.ibm.com[/email] wrote:
Assuming you don't need more granularity than seconds, you should just> Hi all:
>
> I'm trying to determine how long an system operation takes. Anyone know
> of a simple way to do this ?
>
> I wanted to establish the start time. Then run the operation. Then mark
> the finish time. Then substract the start time from the finish time to
> get an elapsed time. Here's the simplistic approach I tried. I'm sure I
> need a time that is measured in seconds or something like that, but I'm
> not sure how to do this.
>
> TIA
>
> Here's what I tried:
>
> #!/usr/bin/perl -w
> use warnings;
> use strict;
>
> my $start = "Tue Jan 27 15:40:16 2004";
> print "This is the start time: $start \n";
>
> system (This is where the system process stuff goes);
>
> my $finish = localtime;
> print "This is the finish time: $finish \n";
>
> my $elapsedtime = ("$finish" - "$start") ;
> print "This is the time diff: $elapsedtime \n";
>
> The above obviously didn't work. Here's what it returned:
>
> This is the start time: Tue Jan 27 15:40:16 2004
> Argument "Tue Jan 27 15:40:16 2004" isn't numeric in subtraction (-) at
> C:\Perl\timetest.pl line 13.
> This is the finish time: Tue Jan 27 19:45:56 2004
> This is the time diff: 0
> Argument "Tue Jan 27 19:45:56 2004" isn't numeric in subtraction (-) at
> C:\Perl\timetest.pl line ClearCase\Us
use 'time'. Don't hardcode the start time either as this seems kind of
pointless, something like:
my $start = time;
system();
my $end = time;
Then subtract the two, that returns # of seconds. perldoc -f time
Depending on what your 'system' is doing you may need to look into
Time::HiRes to get partial second granularity.
[url]http://danconia.org[/url]
Wiggins D'Anconia Guest
-
John W. Krahn #6
Re: How to calculate elapsed time ?
Stuart Clemons wrote:
Hello,>
> Hi all:
Certainly. :-)> I'm trying to determine how long an system operation takes. Anyone know
> of a simple way to do this ?
Hint:> I wanted to establish the start time. Then run the operation. Then mark
> the finish time. Then substract the start time from the finish time to
> get an elapsed time. Here's the simplistic approach I tried. I'm sure I
> need a time that is measured in seconds or something like that, but I'm
> not sure how to do this.
perldoc -f time
my $start = time;> Here's what I tried:
>
> #!/usr/bin/perl -w
> use warnings;
> use strict;
>
> my $start = "Tue Jan 27 15:40:16 2004";
> print "This is the start time: $start \n";
print 'This is the start time: ', scalar localtime $start, "\n";
my $finish = time;> system (This is where the system process stuff goes);
>
> my $finish = localtime;
> print "This is the finish time: $finish \n";
print 'This is the finish time: ', scalar localtime $finish, "\n";
my $elapsedtime = $finish - $start;> my $elapsedtime = ("$finish" - "$start") ;
> print "This is the time diff: $elapsedtime \n";
print "This is the time diff in seconds: $elapsedtime\n";
If you need microseconds instead of seconds look at the Time::HiRes
module.
perldoc Time::HiRes
Also have a look at the Benchmark module.
perldoc Benchmark
John
--
use Perl;
program
fulfillment
John W. Krahn Guest
-
Owen Cook #7
Re: How to calculate elapsed time ?
On Tue, 27 Jan 2004 [email]stuart_clemons@us.ibm.com[/email] wrote:
> I'm trying to determine how long an system operation takes. Anyone know
> of a simple way to do this ?
>
> I wanted to establish the start time. Then run the operation. Then mark
> the finish time. Then substract the start time from the finish time to
> get an elapsed time. Here's the simplistic approach I tried. I'm sure I
> need a time that is measured in seconds or something like that, but I'm
> not sure how to do this.
You might want to look $^T variable.
This variable is the time (secs from 1970) that a perl program is started.
Owen
Owen Cook Guest
-
James Edward Gray II #8
Re: How to calculate elapsed time ?
On Jan 27, 2004, at 6:50 PM, [email]stuart_clemons@us.ibm.com[/email] wrote:
Howdy.> Hi all:
You were on the right track. Try this:> I'm trying to determine how long an system operation takes. Anyone
> know
> of a simple way to do this ?
my $start = time;
# do something to time here
my $time_taken = time - $start;
If you want more information on the time() subroutine, try (at the
commandline):
perldoc -f time
And if you get into timing things it won't be long before you want the
Benchmarking module, generally. You can read about it too:
perldoc Benchmark
Hope that helps.
James
James Edward Gray II Guest
-
Stuart Clemons #9
Re: How to calculate elapsed time ?
Thanks guys. You're the Best !
I used "time" instead of "localtime" and it's exactly what I need for now.
Perl is quickly becoming a very useful tool for me.
Thanks also for the doc info: perldoc -f time & perldoc Benchmark
- Stuart
Stuart Clemons/Westford/IBM wrote on 01/27/2004 07:50:30 PM:
>
> Hi all:
>
> I'm trying to determine how long an system operation takes. Anyone
> know of a simple way to do this ?
>
> I wanted to establish the start time. Then run the operation. Then
> mark the finish time. Then substract the start time from the
> finish time to get an elapsed time. Here's the simplistic approach
> I tried. I'm sure I need a time that is measured in seconds or
> something like that, but I'm not sure how to do this.
>
> TIA
>
> Here's what I tried:
>
> #!/usr/bin/perl -w
> use warnings;
> use strict;
>
> my $start = "Tue Jan 27 15:40:16 2004";
> print "This is the start time: $start \n";
>
> system (This is where the system process stuff goes);
>
> my $finish = localtime;
> print "This is the finish time: $finish \n";
>
> my $elapsedtime = ("$finish" - "$start") ;
> print "This is the time diff: $elapsedtime \n";
>
> The above obviously didn't work. Here's what it returned:
>
> This is the start time: Tue Jan 27 15:40:16 2004
> Argument "Tue Jan 27 15:40:16 2004" isn't numeric in subtraction (-)
> at C:\Perl\timetest.pl line 13.
> This is the finish time: Tue Jan 27 19:45:56 2004
> This is the time diff: 0
> Argument "Tue Jan 27 19:45:56 2004" isn't numeric in subtraction (-)
> at C:\Perl\timetest.pl line ClearCase\UsStuart Clemons Guest



Reply With Quote

