String's indexOf method

Discussion in 'Java' started by Ravi Shankar Nair, Feb 6, 2006.

  1. Dear all,

    During the debugging process of a data handling project, we have seen by a
    profiler that the culprit for long time consuming process is the
    java.lang.String's indexOf method.

    Finally we though of using a C program instead of indexOf method. Can
    anybody provide us a link on such a String class in C or C++, so that we can
    make a faster indexOf ? Thanks a million for your time.

    Best regards,
    Ravi
    Ravi Shankar Nair, Feb 6, 2006
    #1
    1. Advertising

  2. Ravi Shankar Nair

    Eric Sosman Guest

    Ravi Shankar Nair wrote On 02/06/06 10:19,:
    > Dear all,
    >
    > During the debugging process of a data handling project, we have seen by a
    > profiler that the culprit for long time consuming process is the
    > java.lang.String's indexOf method.
    >
    > Finally we though of using a C program instead of indexOf method. Can
    > anybody provide us a link on such a String class in C or C++, so that we can
    > make a faster indexOf ? Thanks a million for your time.


    It's not clear which of the four different indexOf()
    methods you're using. Still, no matter which it is, it
    is probably doing its job nearly as fast as that job can
    be done. You might get a marginally faster something-or-
    other in C or C++, but it's unlikely that you'll get a
    dramatic speedup. Meanwhile, you'd be giving up Java's
    support of international character sets (less than perfect,
    but miles ahead of C and C++), Java's protection against
    out-of-range arguments (especially in C), and so on.

    You're likely to do better not by looking for a faster
    indexOf(), but by considering whether indexOf() is being
    used wisely. Is the program over-using indexOf() when it
    really ought to be using something else? Is it searching
    for a one-character String instead of for a single char?
    Is it always searching from the beginning of the even when
    it's known that the target doesn't appear among the first
    thousand characters? Is it searching Strings that are a
    hundred megabytes in length? Is indexOf() even the right
    tool -- ought you to be using regular expressions, say?

    It's been said that the fastest I/O operation is the
    one you don't perform. "I/O operation" is just a special
    case of a more general observation, of course. I suggest
    you re-examine your reasons for using indexOf() so heavily,
    and consider whether you ought to be using it differently
    or using something else altogether.

    --
    Eric Sosman, Feb 6, 2006
    #2
    1. Advertising

  3. I completely agree! :)
    Ranganath Kini, Feb 6, 2006
    #3
  4. Ravi Shankar Nair

    Alun Harford Guest

    "Ravi Shankar Nair" <> wrote in message
    news:ds7peu$31c$...
    > Dear all,
    >
    > During the debugging process of a data handling project, we have seen by a
    > profiler that the culprit for long time consuming process is the
    > java.lang.String's indexOf method.
    >
    > Finally we though of using a C program instead of indexOf method. Can
    > anybody provide us a link on such a String class in C or C++, so that we

    can
    > make a faster indexOf ? Thanks a million for your time.


    The code for indexOf(String str) probably compiles very well. Also, since
    String is a final class, it's probably actually implemented by hand by the
    writer of the JVM. You are highly unlikely to beat it.

    Alun Harford
    Alun Harford, Feb 6, 2006
    #4
  5. Ravi Shankar Nair

    Joe Attardi Guest

    Slightly off-topic, but hey Eric, don't know if you remember me but I
    used to work in your group at Sun as an intern... good to see a
    familiar face out here in Usenet!

    Joe Attardi
    Joe Attardi, Feb 6, 2006
    #5
  6. Ravi Shankar Nair

    Eric Sosman Guest

    [OT] Re: String's indexOf method

    Joe Attardi wrote On 02/06/06 16:11,:
    > Slightly off-topic, but hey Eric, don't know if you remember me but I
    > used to work in your group at Sun as an intern... good to see a
    > familiar face out here in Usenet!


    Sorta thought you might be that Joe Attardi.
    But this brings up a problem: If somebody out there
    in Usenet actually knows me, my carefully-nurtured
    reputation for sagacity is likely to be exploded by
    the truth ...

    --
    Eric Sosman, Feb 6, 2006
    #6
  7. Ravi Shankar Nair

    Joe Attardi Guest

    Eric Sosman wrote:
    > Sorta thought you might be that Joe Attardi.
    > But this brings up a problem: If somebody out there
    > in Usenet actually knows me, my carefully-nurtured
    > reputation for sagacity is likely to be exploded by
    > the truth ...


    Don't worry. I won't tell. :)
    Joe Attardi, Feb 6, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Klemt
    Replies:
    0
    Views:
    1,146
    Andreas Klemt
    Mar 6, 2004
  2. Guoqi Zheng

    string.indexof case insensitive

    Guoqi Zheng, Jul 9, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    12,882
    bentangle
    Jan 25, 2009
  3. =?Utf-8?B?Q2hyaXMgRGF2b2xp?=

    0=String IndexOf same as empty string.

    =?Utf-8?B?Q2hyaXMgRGF2b2xp?=, Mar 3, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    509
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Mar 3, 2006
  4. Ron Loewy
    Replies:
    3
    Views:
    571
    Dario
    Nov 3, 2003
  5. Michael Berg
    Replies:
    0
    Views:
    471
    Michael Berg
    May 30, 2004
Loading...

Share This Page