Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: Convert time in seconds to hh::mm::ss

by stevieb (Canon)
on Mar 16, 2016 at 02:07 UTC ( [id://1157897]=note: print w/replies, xml ) Need Help??


in reply to Re: Convert time in seconds to hh::mm::ss
in thread Convert time in seconds to hh::mm::ss

It's always preferred to use core modules, but in this case, as opposed to the OP's sub, you'd have to create a new object per conversion (if my brief overview of the module has me understand it correctly):

use warnings; use strict; use Benchmark qw(cmpthese); use Time::Seconds; my $time = '12345678'; cmpthese(1000000, { sub => "parse_duration('$time')", mod => "time_seconds('$time')", }); sub parse_duration { my $seconds = shift; my $hours = int( $seconds / (60*60) ); my $mins = ( $seconds / 60 ) % 60; my $secs = $seconds % 60; return sprintf("%02d:%02d:%02d", $hours,$mins,$secs); } sub time_seconds { my $seconds = shift; my $t = Time::Seconds->new($seconds); return $t->pretty; }

Sometimes it's best just to keep it local:

Rate mod sub mod 17819/s -- -95% sub 373134/s 1994% --

kudos for the other day on the quoting of the var in my own bench, fwiw ;)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1157897]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2026-04-22 21:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.