Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

How to calculate the total time taken to complete the build operation

by perladdict (Chaplain)
on May 09, 2007 at 13:26 UTC ( #614381=perlquestion: print w/ replies, xml ) Need Help??
perladdict has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
I am firing a build on a perticular time like 17:07:53 it will take some time to compile all the binaries.
After all the operation it will generates a log file, which contains all the information about the build
as build start-time 17:07:53 and end_time as 17:39:31. by using these times how can i calculate total time taken for this build.Is there any way to subtract two times as numeric and get the sutracted result to again convert it as timeformat.

Comment on How to calculate the total time taken to complete the build operation
Re: How to calculate the total time taken to complete the build operation
by philcrow (Priest) on May 09, 2007 at 13:58 UTC
Re: How to calculate the total time taken to complete the build operation
by naikonta (Curate) on May 09, 2007 at 14:53 UTC
    In what context you'd like to execute the build? What's your platform? Please be more specific with your problem statement.

    Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!

Re: How to calculate the total time taken to complete the build operation
by thezip (Vicar) on May 09, 2007 at 15:34 UTC

    Update:  BTW, this cannot/does not handle the case where the end date is not the same as the start date. You might want to consider also including the date in your timestring to account for this case (you'll need to also modify my code a bit...)


    Here's a "down-n-dirty" way to do it (with probably a little room for optimization :-)

    #!/perl/bin/perl -w use strict; use Time::Local; my $endtime = "17:39:31"; my $starttime = "17:07:53"; my @end = split(":", $endtime); my @start = split(":", $starttime); my $end_epoch = timelocal(reverse(@end), 1,1,2007); my $start_epoch = timelocal(reverse(@start), 1,1,2007); my $elapsed = $end_epoch - $start_epoch; my $hours = int($elapsed / 3600); my $left = $elapsed - $hours * 3600; my $minutes = int($left / 60); my $seconds = $left % 60; printf "%02d:%02d:%02d\n", $hours, $minutes, $seconds; __OUTPUT__ 00:31:38

    Where do you want *them* to go today?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://614381]
Approved by thezip
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2014-10-02 00:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (41 votes), past polls