Re: qobject_cast
Roger Larsson <[email protected]> Sun, 13 Nov 2005 00:42:09 +0100
| Newsgroups | gmane.comp.kde.devel.optimize |
|---|---|
| Message-ID | <[email protected]> |
On Saturday 12 November 2005 11.18, Olivier Goffart wrote: > Hello. > > When browsing the kdelibs code, i seen sometimes in the code few > qobject_cast when i would used dynamic_cast > > So my question was, what's the difference between qobject_cast and > dynamic_cast ? > > After having doing some test, it seems that qobject_cast is 3 times faster > than dynamic_cast. > > So I'll change my habit, and use qobject_cast instead of dynamic_cast when > casting objects. > > Of course, I must continue to use static_cast which is still 10 times > faster than qobject_cast when i know what my object is. The question is - how do you know this for sure in real applications. (could be true now, but what about early next year) A test on a member variable (enum), or? How much time would such an test add to the static_cast case? (higher optimization levels will probably move that test out of the loop) > > > The attached test, compiled with -O2 > no cast: 11 ms > static_cast: 19ms ratio: 1.72727 > dynamic_cast: 872ms ratio: 79.2727 > qobject_cast: 290ms ratio: 26.3636 dynamic ratio :3.0069 > > note that when i compile with -O0 , static_cast is faster than no cast, > strange.