Skip to content

fmt::string_view ctor under Clang (in pre c++17) much slower than of gcc #914

Closed
@gabime

Description

@gabime

Version: fmt 5.2.1, Clang 6.0

Summary
Constructing fmt::string_view with const char* of size 515 bytes takes about ~180 ns under Clang, while under gcc it takes less than 1ns.

Cause
The cause is that https://github.com/fmtlib/fmt/blob/master/include/fmt/core.h@L217

FMT_CONSTEXPR size_t length(const char *s) { return std::strlen(s); }

is only enabled for gcc (why?) so clang ends up using the much slower implementation (https://github.com/fmtlib/fmt/blob/master/include/fmt/core.h@L210)

Just to be sure I tried to enable for clang as well, and performance went from 180 to 1ns:

#if FMT_GCC_VERSION || defined(__clang__)
FMT_CONSTEXPR size_t length(const char *s) { return std::strlen(s); }
#endif

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions