Re: [JBoss-dev] so how fast is string comparison

2002-02-07 Thread Tomas Lapienis

I'm slightly of topic, anyway

IMHO, Strings are dead slow when comparing to ints.
This is not because of string math (i.e. comparison, etc.)
but because of _new_ and _new_ Strings which takes
part in many methods with Strings involved 
(and almost _every_ String finishes in GC)

So I look at jdk1.4 as a (someway) solver with its
nio.* and regex.* stuff 
LT

 
 Not too bad if the compared strings don't have the same length. Anyway I
 think switch will be always better than if...else.
 
 IMHO I use to work only with int and translate them to String only for
 printing and for input.
 
  I assume a lot as String manipulation is just dead slow, but I could be
  wrong, I really don't know.
 
  marcf
 



___
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development



RE: [JBoss-dev] so how fast is string comparison

2002-02-07 Thread MNewcomb

Most of the strings we are talking about are dynamic (or at least run-time
configurable), so we would have to do string.intern() to be able to use ==
and I don't think that you'd want that internal list of strings growing like
that.  Besides, when you have a new string and do an intern(), it looks up
the common string in a hashtable using hashcode to return the string on
which you can do == on.

Michael

-Original Message-
From: Adam Heath [mailto:[EMAIL PROTECTED]]
Sent: Thursday, February 07, 2002 1:17 PM
To: marc fleury
Cc: Jboss-Development@Lists. Sourceforge. Net
Subject: Re: [JBoss-dev] so how fast is string comparison


On Thu, 7 Feb 2002, marc fleury wrote:

 when we do

 if (string.equals(this))

 else if (string.equals(that))

 how much slower is it than

 switch (stringAsInt)
 case THIS:

 case THAT:

If strings are final, then you can use ==, instead of the much slower
.equals().

A switch stmt is really nothing more than a series of if/elseif blocks.  So,
making all strings static/final, and using ==, should make for a win,
without
making the code hard to read by using abstract ints.



___
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

___
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development



RE: [JBoss-dev] so how fast is string comparison

2002-02-07 Thread Ignacio Coloma

This technique was also proposed in the JDC tech tip of this month, and has
the caveat that a serialized/deserialized String would not work with ==,
even if it was assigned from a static value.

OTOH, the final code translated for a switch depend on the number of 'case'
values. If they're many the compiler should use some kind of binary search
(as a quick sort, but for finding) previously ordering the values. That is
why they are required to be primitive types. When the options are a few,
they're searched lineally to improve performance.

Or it was so the last time I poke around that.

 -Mensaje original-
 De: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED]]En nombre de
 [EMAIL PROTECTED]
 Enviado el: jueves, 07 de febrero de 2002 18:44
 Para: [EMAIL PROTECTED]
 Asunto: RE: [JBoss-dev] so how fast is string comparison


 Most of the strings we are talking about are dynamic (or at least run-time
 configurable), so we would have to do string.intern() to be able to use ==
 and I don't think that you'd want that internal list of strings
 growing like
 that.  Besides, when you have a new string and do an intern(), it looks up
 the common string in a hashtable using hashcode to return the string on
 which you can do == on.

 Michael

 -Original Message-
 From: Adam Heath [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, February 07, 2002 1:17 PM
 To: marc fleury
 Cc: Jboss-Development@Lists. Sourceforge. Net
 Subject: Re: [JBoss-dev] so how fast is string comparison


 On Thu, 7 Feb 2002, marc fleury wrote:

  when we do
 
  if (string.equals(this))
 
  else if (string.equals(that))
 
  how much slower is it than
 
  switch (stringAsInt)
  case THIS:
 
  case THAT:

 If strings are final, then you can use ==, instead of the much slower
 .equals().

 A switch stmt is really nothing more than a series of if/elseif
 blocks.  So,
 making all strings static/final, and using ==, should make for a win,
 without
 making the code hard to read by using abstract ints.



 ___
 Jboss-development mailing list
 [EMAIL PROTECTED]
 https://lists.sourceforge.net/lists/listinfo/jboss-development

 ___
 Jboss-development mailing list
 [EMAIL PROTECTED]
 https://lists.sourceforge.net/lists/listinfo/jboss-development




___
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development