TITLE: runtime cost of exceptions (Newsgroups: comp.lang.c++.moderated) PROBLEM: pcm@scammell.ecos.tne.oz.au (Peter Murray) [...] (How does exception handling affect size/performance?) RESPONSE: rmartin@oma.com (Robert C. Martin), 11 Apr 96 I recently did a timing analysis of BC4.51 running on a 486-33 laptop. Exceptions on Exceptions off lt .329us 0.34us nv 1.001us 0.954us voh 0.136us (13.58%) 0.137us (13.9%) snvcd 3.593us 2.142us svcdoh 0.324us (9.02%) 0.331us (15.5%) hnvcd 5.1us 2.472us hvcdoh 3.53us (69.2%) 1.269us (51.3%) ==================================================== lt The time for a single interation of an empty for loop. This was done to calibrate the model. all the other timings were taken from 1e7 such loops. for (long i=0; i<10000000; i++); The next two metrics come from the following class: class F { public: void nv(); virtual void v(); }; void F::nv() {} void F::v() {} F f; F& fr=f; nv The time for calling a non-virtual function through a reference to an object. The function had no arguments and no body. i.e. time for a call to f.nv(); voh Virtual Overhead. The extra time required for calling a virtual function through a reference to an object. i.e. this is the time for f.v(); minus the time for f.nv(); snvcd Time to create and destroy on the stack an object with no virtual functions. i.e. the time for: {O o;} where O is a class with no virtual functions and no data elements. svcdoh Virtual overhead. The extra time, above and beyond snvcd, to create and destroy an object on the stack; where the object has a virtual destructor and no data elements. hnvcd Time to create and destroy on a degenerate heap, an object with no virtual functions or data elements. i.e. time for: {delete new O;} where operator new and operator delete have been overridden to do nothing. hvcdoh Virtual overhad. The extra time, above and beyond hnvcd to create and destroy, on the heap, an object with a virtual destructor and no data elements.