On Thu, 2024-08-15 at 18:17 -0400, Olivier Langlois wrote: > > To my eyes, what is really important, it is that absolute best > technical solution is choosen and the only way that this discussion > can > be done, it is with numbers. So I have created a small created a > small > benchmark program to compare a function pointer indirect call vs > selecting a function in a 3 branches if/else if/else block. Here are > the results: > > ---------------------------------------------------------- > Benchmark Time CPU Iterations > ---------------------------------------------------------- > BM_test_virtual 0.628 ns 0.627 ns 930255515 > BM_test_ifElse 1.59 ns 1.58 ns 446805050 > I have fixed my benchmark: ---------------------------------------------------------- Benchmark Time CPU Iterations ---------------------------------------------------------- BM_test_virtual 2.57 ns 2.53 ns 277764970 BM_test_ifElse 1.58 ns 1.57 ns 445197861 code: using Func_t = bool (*)(); bool testVirtual(Func_t ptr) { return ptr(); } void BM_test_virtual(benchmark::State &state) { volatile Func_t ptr = &static_tracking_do_busy_loop; for (auto _ : state) { benchmark::DoNotOptimize(testVirtual(ptr)); } }