Cost of having try-catch statements?
Reshat Sabiq
sabiq@csociety.ecn.purdue.edu
Tue Aug 24 06:58:00 GMT 2004
Actually, since this is cost for 10 million method try-catch blocks, i
conclude that the cost per single try-catch block is negligible. Thus, i
don't have to do any special logic to avoid try-catch in my case, which
appears to be true in
general.
Thanks,
<rsa/>
On Mon, 23 Aug 2004, Reshat Sabiq wrote:
> OK, i think i just got onto the same page with this thread. The cost in
> 1.3.1_05 is negligible (similar to Linux, even smaller). The cost in 1.4.2
> and 1.5.0, however, is not negligible.
> Now i conclude that it is best to avoid try-catch if possible, for
> genericness sake. I will have to provide some logic for this in my case,
> to save the .12-.18 seconds in the long term.
> It is suprising, however, that the cost on Linux is so small, w/ no
> try-catch case being around 200ms. What was the hardware on that test? I
> would shout out Linux rules if this metric goes down dramatically (to
> 50-60ms) on good hardware. Will try to test myself later...
>
> This is the table i got (2000 only has 1.3.1 values):
> Try-Catch XP Plain XP
> 2000 1.3.1_05 1.4.2_04 1.5.0 2000 1.3.1_05 1.4.2_04 1.5.0
> 297 230 231 180 266 210 60 60
> 296 220 240 171 266 221 50 50
> 282 231 230 170 281 210 60 60
> 297 220 241 171 281 220 50 60
> 297 230 231 180 266 210 50 60
> 297 220 230 170 265 221 60 50
> 297 230 230 180 266 211 50 60
> 328 221 241 171 281 220 60 50
> 297 230 231 180 266 211 50 60
> 297 221 230 180 265 250 60 50
> 281 231 230 170 281 210 50 60
> 296 220 231 170 282 220 60 51
> 282 230 240 180 281 210 50 60
> 312 220 241 180 281 221 50 50
> 282 220 240 170 281 210 50 60
> 328 220 241 180 281 251 50 51
> 281 220 230 170 282 211 51 70
> 328 220 230 170 281 220 60 60
> 297 221 240 171 265 210 50 60
> 281 220 230 170 266 220 50 60
> 5953 4475 4688 3484 5484 4367 1071 1142
> 1.085521517 1.024730937 4.377217554 3.050788091
> 297.65 223.75 234.4 174.2
>
> Thanks,
> <rsa/>
>
> On Mon, 23 Aug 2004, Reshat Sabiq wrote:
>
> > > Eh. Maybe my mind is going, but I thought I'd seen a patch to unwind
> > > over Windows callbacks.
> >
> > > Andrew.
> >
> > This was my question for the past couple of days as well. While i'm not
> > versed in the machine language instructions involved, i expected the
> > overhead to be minimal, just by thinking how i would implement exception
> > handling.
> > I would like to ask what platform was the 4-5 times overhead seen on in
> > Windows? I just tried the same Main class mentioned by Harald on both
> > Windows 2000 and Windows XP using SDK 1.3.1_05. After averaging 10
> > executions, the overhead i've seen on 2000 is 8.55%, and on XP it is
> > 2.47%. If we considered a method with millions or billions of instructions
> > inside, the overhead would be totally miniscule.
> > The times i'm getting w/ try-catch are 297.65ms on 2000, and 223.75ms on
> > XP.
> >
> > In general, based on this simple test and the common sense, i'm concluding
> > that it is safe to assume that try-catch w/o the exception thrown has
> > negligible overhead. While i'm cognizant of GCC builds for Windows from
> > MinGW mentioned by Ranjit, that doesn't appeat to apply in most other
> > applicable cases, such as when using the regular Sun JVMs and bye-code.
> >
> > Thanks,
> > <rsa/>
> >
> >
>
>
More information about the Java
mailing list