Boost logo

Boost :

Subject: Re: [boost] [type_index] Interest in dynamic_cast emulation?
From: Chris Glover (c.d.glover_at_[hidden])
Date: 2016-07-17 12:45:57


I've written a better benchmark for emulated dynamic_cast (runtime_cast) vs
built in dynamic_cast and the results are surprising.

In my initial naive test, the compiler was able to optimize because it knew
the concrete types, in this test, I've made sure the concrete types are
unknown by using factory functions implemented in another translation unit.
With this method it looks like runtime_cast is never slower than
dynamic_cast, and usually faster by some margin. The amount of difference
depends on the compiler.

The benchmark is available on github:

git clone --recursive

>From there, you should just be able to simply configure via cmake and build
(all of the relevant code, including the modified typeindex, is included).
The test could be more comprehensive, but so far I am convinced this is a
good solution. I've added a couple of charts from two of tests here (GCC
5.3 and MSVC 19.0).

This one is showing the cast distance (ie: how far from the most derived
class to the class we're trying to cast to) vs time to do the cast, for a
single inheritance chain only (ie: no branches in the tree).

This one is showing the cast distance vs time to do the cast, for a
multiple virtual inheritance chain. This one doesn't go as deep just
because of number of classes needed.

Feedback welcome.

-- chris

Boost list run by bdawes at, gregod at, cpdaniel at, john at