Hello,
I just did a simple benchmark:
for (xx=0;xx<100000 ;xx++) {
rDerived* derived = dynamic_cast<rD erived*>(object );
if (derived) derived->setValue(messa ge.data.message SetInt.value);
}
against:
for (xx=0;xx<100000 ;xx++) {
if (typeid(object) == typeid(rDerived *)) ((rDerived*)
object)->setValue(messa ge.data.message SetInt.value);
}
And the latter case blew the former out of the water. Using typeid() with a
C style cast was 94 times faster than using dynamic_cast<>.
So is it really better to use typeid() and a C style cast rather than the
(apparantly) slower dynamic_cast<>?
Jamie Burns.
I just did a simple benchmark:
for (xx=0;xx<100000 ;xx++) {
rDerived* derived = dynamic_cast<rD erived*>(object );
if (derived) derived->setValue(messa ge.data.message SetInt.value);
}
against:
for (xx=0;xx<100000 ;xx++) {
if (typeid(object) == typeid(rDerived *)) ((rDerived*)
object)->setValue(messa ge.data.message SetInt.value);
}
And the latter case blew the former out of the water. Using typeid() with a
C style cast was 94 times faster than using dynamic_cast<>.
So is it really better to use typeid() and a C style cast rather than the
(apparantly) slower dynamic_cast<>?
Jamie Burns.
Comment