[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-optimize
Subject:    Re: qobject_cast
From:       Roger Larsson <roger.larsson () norran ! net>
Date:       2005-11-12 22:45:02
Message-ID: 200511130042.09595.roger.larsson () norran ! net
[Download RAW message or body]

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.
_______________________________________________
Kde-optimize mailing list
Kde-optimize@kde.org
https://mail.kde.org/mailman/listinfo/kde-optimize
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic