You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by David Kerber <dc...@verizon.net> on 2006/08/07 17:59:52 UTC

Code performance question #2

This code is part of a servlet running in TC 5.5.12, jre ver 1.5.0.6.

I use this code to break out individual data fields from a line which is 
structured as  "a=11111&b=22222&c=333333333&d=44444&e=5".  It is 
executed for over 2 million data lines per day, so this routine is 
executed over 10 million times per day.  All the fields are short ( < 10 
chars) except the 5th one, which can be up to about 40 characters.  Is 
there a more cpu-efficient way of doing this, or is this about as good 
as it gets?

    private static String getField ( String fieldName, String dataString ) {
        Integer    ii, kk;

        ii = dataString.indexOf( fieldName + "=" );
        if (ii == -1 ) return null;
        kk = dataString.indexOf( "&", ii );
        if ( kk.equals( -1 )) {
            kk = dataString.length();
        }
        return ( dataString.substring( ii + 2, kk ));
    }

TIA!
Dave



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Code performance question #2

Posted by David Kerber <dc...@verizon.net>.
See my response to Peter; I can't control the format of that data string 
(it's from a different application).  I just need to split out the data 
fields and store them away in a disk file.  Or am I missing the point of 
your suggestion?

Dave


Leon Rosenberg wrote:

> thats ugly, why don't you tokenize it into string pairs, store the
> pairs and works with them?
> leon
>
> On 8/7/06, David Kerber <dc...@verizon.net> wrote:
>
>> This code is part of a servlet running in TC 5.5.12, jre ver 1.5.0.6.
>>
>> I use this code to break out individual data fields from a line which is
>> structured as  "a=11111&b=22222&c=333333333&d=44444&e=5".  It is
>> executed for over 2 million data lines per day, so this routine is
>> executed over 10 million times per day.  All the fields are short ( < 10
>> chars) except the 5th one, which can be up to about 40 characters.  Is
>> there a more cpu-efficient way of doing this, or is this about as good
>> as it gets?
>>
>>     private static String getField ( String fieldName, String 
>> dataString ) {
>>         Integer    ii, kk;
>>
>>         ii = dataString.indexOf( fieldName + "=" );
>>         if (ii == -1 ) return null;
>>         kk = dataString.indexOf( "&", ii );
>>         if ( kk.equals( -1 )) {
>>             kk = dataString.length();
>>         }
>>         return ( dataString.substring( ii + 2, kk ));
>>     }
>>
>> TIA!
>> Dave
>



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Code performance question #2

Posted by Leon Rosenberg <ro...@googlemail.com>.
thats ugly, why don't you tokenize it into string pairs, store the
pairs and works with them?
leon

On 8/7/06, David Kerber <dc...@verizon.net> wrote:
> This code is part of a servlet running in TC 5.5.12, jre ver 1.5.0.6.
>
> I use this code to break out individual data fields from a line which is
> structured as  "a=11111&b=22222&c=333333333&d=44444&e=5".  It is
> executed for over 2 million data lines per day, so this routine is
> executed over 10 million times per day.  All the fields are short ( < 10
> chars) except the 5th one, which can be up to about 40 characters.  Is
> there a more cpu-efficient way of doing this, or is this about as good
> as it gets?
>
>     private static String getField ( String fieldName, String dataString ) {
>         Integer    ii, kk;
>
>         ii = dataString.indexOf( fieldName + "=" );
>         if (ii == -1 ) return null;
>         kk = dataString.indexOf( "&", ii );
>         if ( kk.equals( -1 )) {
>             kk = dataString.length();
>         }
>         return ( dataString.substring( ii + 2, kk ));
>     }
>
> TIA!
> Dave
>
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org