Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: The performance cost of using exceptions?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Frank Atanassow <franka@c...>
Subject: Re: The performance cost of using exceptions?
Markus Mottl writes:
 > > Are programs written to make heavy use of exceptions going to be markedly
 > > slower than programs written more traditionally with loops/ifs, etc?
 > 
 > That depends on how you use them. It is well possible to do this in such a
 > way that you actually increase performance.
 > 
 > For example, when inserting elements into a binary tree, the naive version
 > always copies the "spine" of the tree, even if the element is already a
 > member.
 > 
 > But if you use exceptions, you can "jump back" and can thus prevent the
 > spine from being copied. This normally reduces the load of the garbage
 > collector and yields some percent more performance.

I don't see how this would improve performance. If the element is in the tree,
you will be copying the spine until you descend to a point where you discover
the node exists. If you then escape via an exception, the copied nodes will be
collected. Otherwise (but it depends on your specification, I suppose) the
functional way would be to just return the subtree(s) intact, so there would
be no need to copy their spines. Either way, you're generating the same amount
of garbage.

-- 
Frank Atanassow, Dept. of Computer Science, Utrecht University
Padualaan 14, PO Box 80.089, 3508 TB Utrecht, Netherlands
Tel +31 (030) 253-1012, Fax +31 (030) 251-3791