Hello,

I was reading the mailing list archive of classpath
(interrested, but no time to code:(

I saw the topic of using exceptions for error checking.
I have only one response: don't

It is terribly slow as the attached code shows. These are the
timings i've got (all times are in milliseconds):

(marcel@rincewind:0) ~/java> java Benchmark
Time= 1821
Time= 1681
Time= 1356
(marcel@rincewind:0) ~/java> java -Djava.compiler=tya Benchmark
TYA 0.7 (for J116) loaded. Copyright (c) 1997,98 The TYA Team
Contact  The TYA Team   via Albrecht Kleine  <[EMAIL PROTECTED]>
Time= 1303
Time= 1307
Time= 165

The first two times use an exception for the error condition while
the last one uses an explicit check. Although a try/catch clause looks
like less work on the source-code level, the JVM must do a lot more
in this case. Therefore exceptions should only be used to the case their name
refers to: in exceptional cases.

Marcel Ammerlaan

ps. i'll be watching the list to see if any more optimalisations can be
applied as I've gotten rather sick of the speed of Java:)
-- 
I trust you trust in me to mistrust you
 - Fish

Reply via email to