[EMAIL PROTECTED] wrote:
>
> Hi all,
>
> In many classes, to detect the need of array-resizing, we try to access a
> specific position, and do the resizing when
> "ArrayIndexOutOfBoundsException" is caught (or NullPointerException for
> multidimensional arrays).
>
> But my understanding is that throw-catch exceptions is much more expensive
> than get the array size directly: arrayVal.length. So there would be a big
> performance hit if we resize arrays frequently. (In fact, we do resize
> StringPool very often.)
When measuring performance there are lots of variables that need to be
taken into account. In particilar, in the case you mention, I believe
the JVM that you measure with can make a difference on which method is
faster. My guess is that the code was tuned for a particular JVM in
which catching exceptions was faster, but that the JVM you measured with
has the opposite characteristic. For example, I've seen a JVM where
certain Java exceptions where implemented using hardware trap
instructions on x86 architectures, so the code would run faster in that
case. But, what eventually happens is that time passes and JVMs change
but not the code so the high level "performance tuning" is no longer
valid on newer JVMs so you end up with code that is difficult to
understand and may even perform worse compared to the straightforward
code.
So IMHO, the better approach to writing code like this would be to make
the code easily understandable and maintainable and let the JVM handle
the optimization.
-Edwin
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]