in reply to Re: Equation - code review
in thread Equation - code review

Hi,
Thanks for your reply.
The output of the program is exactly correct which I have checked against the manual work. The performance issue can arise when my given input string is more than 1000 characters.
Can you please suggest me, how to improve the performance inside the loops ?
- kulls

Replies are listed 'Best First'.
Re^3: Equation - code review
by imp (Priest) on Aug 16, 2006 at 07:43 UTC
    You have been very polite and my inclination is to help you. Please make it easier to do so.

    You have provided us with your current solution to a problem, but you haven't specified what that problem is. It is difficult to identify what areas might be unneccesary or wasteful in this situation.

    Some inline documentation would be useful, as would some additional comments in this thread. Here are a few things that would be nice to know:

    • Why is $distance_index and $window random
    • More sample data. The $sequence provided is 7 characters, but in this comment you state that it can be over 1000 characters in length. The size of the input data will help determine which algorithm is appropriate.
    • How often will this function be called
      Hi,
      User can send the different values of distance, window and sequence as well. through CGI interface and this refined subroutine will be used inside the package and all the validation controlled by the CGI itself.
      . I need to extend my functionality based on this single subroutine , Hence I need to sort it out all the obstacles.My observation is, concerned with Math::Bigint package which created a new object (inside the forloop), I'm using  substr method to pare the characters.
      Can you please suggest me, If any where I can improve the performance.
      - kulls
Re^3: Equation - code review
by imp (Priest) on Aug 16, 2006 at 08:00 UTC
    Before you start optimizing your code I recommend writing a test suite that verifies the current behaviour. That way when you introduce errors during optimization they will be easier to spot. You have done the manual verification, put that in a test script.

    For example you could do this (and leave alpha_index as it is):

    #!c:\perl\bin\perl use strict; use warnings; use Math::BigInt; use Data::Dumper; use Test::More qw(no_plan); my %index_val = ( A => 2, C => 3, D => 4, N => 2, M => 2, T => 1, G => 4); my $sequence = "ACTGACN"; my $distance_index = 3; my $window = 2; my $arr_ref = alpha_index({ sequence => $sequence, distance => $distance_index, aa_index => \%index_val, window_size => $window }); ok($arr_ref); diag("Testing alpha_index with window: $window, distance: $distance_in +dex, sequence: $sequence"); is(ref($arr_ref),'ARRAY','alpha index returned an array'); is(@$arr_ref,7,'7 entries are in the array'); is($arr_ref->[0]{A},2.51025682971601);
    Take a look at Test::More for other ideas on what you can test.