[Biojava-l] Performance of SymbolList.subStr() function

Andy Hammer facemann at yahoo.com
Fri Sep 12 20:05:10 EDT 2003


This blows my mind!
In both blocks of code:  seq = si.nextSequence();
//just a protein sequence

In this block of code, my system would take hours and
often crash with an out of memory error.

     for(int i = 1; i <= seqLength; i++){
        String seqString = seq.subStr(i,i);
        char protein = seqString.charAt(0);
        newSeq =
newSeq.append(newCodon(protein));//add a 3 char string
to the newSeq StringBuffer
      }

I altered the above block to:

    String seqString = seq.seqString();
    for(int i = 0; i < seqLength; i++){
      char protein = seqString.charAt(i);
      newSeq = newSeq.append(newCodon(protein));
    }

This program used to take 4 hours to complete.  With
this simple change it is now done in 30 minutes! 
Obviously, the SymbolList.subStr() function was
severly hampering my efficiency.  I guess it was poor
use of the SymbolList.subStr() function.  My rational
was that I didn't want to create an unneeded String
simply to represent my already existing SymbolList.  I
am just trying to learn from this to become a better
programmer and would appreciate any comments on this.

Thanks!

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com


More information about the Biojava-l mailing list