//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include #include #include #include "benchmark/benchmark.h" template struct C : public virtual C, public virtual C { virtual ~C() {} }; template struct C { virtual ~C() {} }; template struct B : public virtual C, public virtual C {}; template struct makeB; template struct makeB, Depth> : public B... {}; template struct A : public makeB, Depth> {}; constexpr std::size_t Width = 10; constexpr std::size_t Depth = 5; template void CastTo(benchmark::State& state) { A a; auto base = static_cast*>(&a); Destination* b = nullptr; for (auto _ : state) { b = dynamic_cast(base); benchmark::DoNotOptimize(b); } assert(b != 0); } BENCHMARK(CastTo>); BENCHMARK(CastTo>); BENCHMARK_MAIN(); /** * Benchmark results: (release builds) * * libcxxabi: * ---------------------------------------------------------------------- * Benchmark Time CPU Iterations * ---------------------------------------------------------------------- * CastTo> 1997 ns 1997 ns 349247 * CastTo> 256 ns 256 ns 2733871 * * libsupc++: * ---------------------------------------------------------------------- * Benchmark Time CPU Iterations * ---------------------------------------------------------------------- * CastTo> 5240 ns 5240 ns 133091 * CastTo> 866 ns 866 ns 808600 * * */