| Author |
Questions on Speed for String Parsing/Comparisons
|
Robert Paris
Ranch Hand
Joined: Jul 28, 2002
Posts: 585
|
|
Many times I find I have a need to parse a string, looking for another string value inside, or compare strings. I know that String actions eat alot of time/resources, so I'm looking for a way to speed this up. One idea I had was to convert all my Strings to byte[] objects, but I have no idea if this is faster, nor if it's the quickest way to do this. Does anyone know the best way? For example, let's say I have a String that comes in from an email that is this: "Hey Robert,\r\nWhat's been going on?\r\n" I want to find all the cases of "\r\n" or, if the program that sent the message used "\n" instead of "\r\n", then i want to find all those. What's the fastest way to do this? Thanks in advance!
|
 |
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
|
|
Well, you can expect the String methods to already be maximally optimized, so there really is no reason to do something like a conversion to byte[] or the like (String *is* working on char[] internally). In some cases, intelligent use of regular expressions might be more effective than indexOf() and the like, but it's hard to say in general. Anyway, I would suggest using a profiler first to get more info on where your performance bottlenecks are - you might be surprised...
|
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
|
 |
 |
|
|
subject: Questions on Speed for String Parsing/Comparisons
|
|
|