[Bioperl-l] Re: issues with _rearrange

Hilmar Lapp hlapp@gnf.org
Fri, 20 Sep 2002 12:02:39 -0700


The following variation turns out to be even marginally faster (perl 
5.6.0, Mac OSX 10.1.5), and has the benefit of not removing 
intervening hyphens:

sub new_rearrange2 {
     my ($self, $order) = (shift,shift);
     return @_ unless ($#_ % 2 && substr($_[0]||'',0,1) eq '-');
     my $i = 0;
     my %param = map { $i++ % 2 ? $_ : substr(uc($_),1); } @_;
     return @param{@$order};
}

In a bit more readable way,

sub new_rearrange2 {
     my ($self, $order) = (shift,shift);
     return @_ unless ($#_ % 2 && substr($_[0]||'',0,1) eq '-');
     my %param;
     while (@_) {
		my $key = substr(uc(shift),1);
         $param{ $key } = shift;
     }
     return @param{@$order};
}

appears to have about the same speed.

	-hilmar

On Friday, September 20, 2002, at 11:14 AM, Hilmar Lapp wrote:

>
> On Friday, September 20, 2002, at 09:39 AM, Ewan Birney wrote:
>
>>
>> Tim - you are a legend.
>>
>>
>> guys - I am planning to apply Tim's new _rearrange now at least 
>> which is a
>> definite win for most other routes right? Any objections?
>>
>>
>
> If you don't do it, I'll do. ;-)
>
> Tim, two questions: the conclusion is that s// is slower (~2x) than 
> tr//? Would substr($_,0,1,"") (for removing the initial hyphen) 
> give away the speedup, two?
>
> 	-hilmar
> --
> -------------------------------------------------------------
> Hilmar Lapp                            email: lapp at gnf.org
> GNF, San Diego, Ca. 92121              phone: +1-858-812-1757
> -------------------------------------------------------------
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l@bioperl.org
> http://bioperl.org/mailman/listinfo/bioperl-l
>
--
-------------------------------------------------------------
Hilmar Lapp                            email: lapp at gnf.org
GNF, San Diego, Ca. 92121              phone: +1-858-812-1757
-------------------------------------------------------------