• Post Reply Bookmark Topic Watch Topic
  • New Topic

which would gives the greater performance ?whether StringTokenizer or split method of string

 
Birla Murugesan
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

which would gives the greater performance? whether StringTokenizer or split method of string

explain with exampls
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at comparison here. Split is easier to use relatively. I mostly prefer to use split(), its quite handy and clean.
 
Tim Holloway
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Birla Murugesan wrote:
explain with exampls


What? This is a homework assignment?

Besides, this is a classic case where you should measure how your specific workload performs.
 
Birla Murugesan
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:
What? This is a homework assignment?

Besides, this is a classic case where you should measure how your specific workload performs.


ok,Anyway ,please try to answer my technical question also......
 
Tim Holloway
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Birla Murugesan wrote:
ok,Anyway ,please try to answer my technical question also......


I did. Measure it. The idea of "best" is false. Algorithms have optimal and sub-optimal uses. If you were were approach the idea from a purely theoretical case, you might say that tokenizing is more complex, so the split method would be "best". But on classic IBM mainframes, there's a single machine-language instruction that can do tokenizing, where general regular-expression based splitting might require multiple instructions. More recent mainframes have entire C library functions in their instruction set, and it's possible that an RE parser is one of them - I haven't checked. Depending on what the typical datastream is and what methods - and what hardware - are used to accomplish the methods, the "best" option will vary

So the only realistic approach is to set up something approaching your real-world offensive cases and try both.

And it should be a real-world need. Premature optimization is one of the things we often point out is best avoided. Most apps don't spend nearly enough time tokenizing/splitting for it to be worth the expense in tuning.
 
Birla Murugesan
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:
So the only realistic approach is to set up something approaching your real-world offensive cases and try both.

Most apps don't spend nearly enough time tokenizing/splitting for it to be worth the expense in tuning.


But, In Sun java ApI docs itself recommended to use split method of string instead of StringTokenizer

what you say?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35709
408
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Birla Murugesan wrote:But, In Sun java ApI docs itself recommended to use split method of string instead of StringTokenizer

Absolutely. They are recommending that for clarity though. split() is clearer and more powerful. It is also more likely to be tuned in the future regardless of which is faster now.

Adeel did answer your question - split() was benchmarked to be faster. Everyone else pointed out you should benchmark if yourself if you have a real reason to worry about it.
 
Eric Schwarzenbach
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you read the graph wrong, Jeanne, it showed StringTokenizer to be faster.
 
bernard amadeus
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Birla Murugesan wrote:
But, In Sun java ApI docs itself recommended to use split method of string instead of StringTokenizer

what you say?


I say this: doc recommendation is misleading : try to parse something which has two consecutive "space" characters ...
split used indiscriminately and StringTokenizer won't yield the same result.

so my advice: if you just parse simple "space separated" String use StringTokenizer (using advanced pattern on split is just too cumbersome).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!