Talk:cpp/language/attributes/likely

This page contains a detailed example with a possible output of running that code, that shows a significant runtime improvement caused by using. However, the numbers seem quite optimistic, and I was not able to reproduce this effect at all (I tried with both gcc and clang on an x86). Does anyone have any insights on how to get such results? E.g. some compiler + processor combination that could produce it?

For reference, it was added in this edit by Space Mission: https://en.cppreference.com/mwiki/index.php?title=cpp/language/attributes/likely&diff=125917&oldid=124529

Tomerv (talk) 10:34, 8 June 2022 (PDT)


 * my PC (Xeon W-2145) is fairly consistently showing this difference, with gcc 11.3:


 * and I even rotated the lines around in the source in case it's some cache warmup, and the numbers persisted:


 * so.. works for me --Cubbi (talk) 14:08, 8 June 2022 (PDT)


 * I ran it on visual studio for funsies, and I got


 * and in GCC 11.1 on my ubuntu WSL


 * For extra funsies, GCC 9.4 gives me


 * Suffice to say that mileage here is very varying --Ybab321 (talk) 02:42, 9 June 2022 (PDT)


 * Thank you both for taking the effort to check. Cubbi, I think that -O3 is the key here:


 * Ybab321, did you compile with -O3?
 * Tomerv (talk) 09:44, 13 June 2022 (PDT)


 * I compiled with as well, to my surprise  does replicate the desired results on GCC 11.1!


 * On GCC 9.4 there's no significant difference (unsurprisingly). Guess I need to show some more respect in the future --Ybab321 (talk) 14:02, 13 June 2022 (PDT)
 * According to the GCC status they added  attributes support in GCC-9, but empirically, the optimal code generation was ready since GCC-10. Godbolt (with this example) is quite expressive on this.) --Space Mission (talk) 15:36, 13 June 2022 (PDT)