Chas. Owens wrote: > On Wed, Aug 11, 2010 at 08:39, Â <[email protected]> wrote: > snip >> I probably should have mentioned that the "Matt" code is >> what is currently being used in production and I need to >> profile/benchmark it against different approaches. > snip > > Just getting rid of the stupid in your production code > increases the > speed by between forty and fifty percent (at least on OS > X). It also > drops the line count from twelve to three. > > #!/usr/bin/perl > > use strict; > use warnings; > use POSIX qw(strftime); > use Benchmark qw(:all); > > cmpthese(-1, { > production => \&production, > experimental => \&experimental, > }); > > > sub production { > my $now_date_epoch = time(); > my $BDtarget = ($now_date_epoch - 5); > my > ($Bsec,$Bmin,$Bhour,$Bmday,$Bmon,$Byear,$Bwday,$Byday,$Bisdst) > = localtime($BDtarget); > $Byear = ($Byear + 1900); > $Bmon++; > if ($Bmon < 10) {$Bmon = "0$Bmon";} > if ($Bmday < 10) {$Bmday = "0$Bmday";} > if ($Bhour < 10) {$Bhour = "0$Bhour";} > if ($Bmin < 10) {$Bmin = "0$Bmin";} > if ($Bsec < 10) {$Bsec = "0$Bsec";} > my $BDtsSQLdate = "$Byear$Bmon$Bmday$Bhour$Bmin$Bsec"; > } > > sub experimental { > my ($s, $min, $h, $d, $mon, $y) = localtime(time - 5); > my $BDtsSQLdate = sprintf "%d%02d%02d%02d%02d%02d", $y > + 1900, > $mon + 1, $d, $h, $min, $s; > } > > > > -- > Chas. Owens
That looks like it might be the best correction and will most likely be what I'll use, but I'd like to test 1 or 2 other possibilities. Thanks, Ron -- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] http://learn.perl.org/
