3 ms·
> This is a fun benchmark in C++, where you can see that GCC has a more restrictive small string optimization Wouldn't this be on the choice of stl (libstdc++
by moonchild 6y ago
> This is a fun benchmark in C++, where you can see that GCC has a more restrictive small string optimization
Wouldn't this be on the choice of stl (libstdc++ vs libc++) rather than compiler?
Anyway, on my system, (llvm/clang 10.0, gcc 10.1), both take ~360ms.
> None of the compilers can see that the loop can be optimized out
I was interested in this, so decided to investigate. I'm actually not sure why that's happening. This is the definition of to_string on my system:
inline string
to_string(long __val)
{
const bool __neg = __val < 0;
const unsigned long __uval = __neg ? (unsigned long)~__val + 1ul : __val;
const auto __len = __detail::__to_chars_len(__uval);
string __str(__neg + __len, '-');
__detail::__to_chars_10_impl(&__str[__neg], __len, __uval);
return __str;
}
__to_chars_len() is marked as 'constexpr', but __to_chars_10_impl is not, and the latter modifies an allocated buffer; maybe that's why?
- stabbles 6y agoNice, maybe std::string has changed in GCC 10, I was using GCC 9. Shouldn't C++20 have constexpr containers?