Open firewave opened 1 year ago
Split from #58002.
#include <string> #define LITERAL_S "012345678901234" #define LITERAL_L "0123456789012345" bool cmp3_s(const std::string& s) { const std::string s_s(LITERAL_S); return s == s_s; } bool cmp4_s(const std::string& s) { static const std::string s_s(LITERAL_S); return s == s_s; } bool cmp3_l(const std::string& s) { const std::string s_s(LITERAL_L); return s == s_s; } bool cmp4_l(const std::string& s) { static const std::string s_s(LITERAL_L); return s == s_s; }
https://quick-bench.com/q/A3FPfNV6Cds2TwwBvSRwT6klxLg
This applies to all strings with less than 16 characters.
This does not happen with GCC where static is always faster no matter the length: https://quick-bench.com/q/hPor-y8JDwcMBEnT_oOv79nF43g https://quick-bench.com/q/4Ef2dOfaBuhCd0QkKBRVVCXamjI
static
Using -O3 improves things but it is still slower: https://quick-bench.com/q/q1dTqCGNfLvOLHW5ZI_vV4Io91c
-O3
Only starting with C++-20 it yields the expected result: https://quick-bench.com/q/DoPeAkL3TzHA_aw_RrykbZyRgOc
Split from #58002.
https://quick-bench.com/q/A3FPfNV6Cds2TwwBvSRwT6klxLg
This applies to all strings with less than 16 characters.
This does not happen with GCC where
static
is always faster no matter the length: https://quick-bench.com/q/hPor-y8JDwcMBEnT_oOv79nF43g https://quick-bench.com/q/4Ef2dOfaBuhCd0QkKBRVVCXamjI