Re: The performance cost of using exceptions?

From: Frank Atanassow (franka@cs.uu.nl)
Date: Tue May 16 2000 - 11:30:14 MET DST

  • Next message: Hongwei Xi : "Re: reference initialization"

    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
    



    This archive was generated by hypermail 2b29 : Tue May 16 2000 - 12:42:02 MET DST