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 ;)
|
|---|