|
10 | 10 | #include <sstream>
|
11 | 11 | #include <string>
|
12 | 12 |
|
| 13 | +#if __has_include(<format>) |
| 14 | +# include <format> |
| 15 | +#endif |
| 16 | + |
13 | 17 | namespace {
|
14 | 18 |
|
15 | 19 | using StringTable = fly::benchmark::Table<std::string, double>;
|
@@ -69,8 +73,29 @@ class FmtFormat : public StringBase
|
69 | 73 | }
|
70 | 74 | };
|
71 | 75 |
|
| 76 | +#if __has_include(<format>) |
| 77 | + |
| 78 | +// std::format |
| 79 | +class StdFormat : public StringBase |
| 80 | +{ |
| 81 | +public: |
| 82 | + void format_with_floats() override |
| 83 | + { |
| 84 | + FLY_UNUSED( |
| 85 | + std::format("{:.10f}:{:04}:{:+}:{}:{}:{}:%\n", 1.234, 42, 3.13, "str", nullptr, 'X')); |
| 86 | + } |
| 87 | + |
| 88 | + void format_without_floats() override |
| 89 | + { |
| 90 | + FLY_UNUSED( |
| 91 | + std::format("{:10}:{:04}:{:+}:{}:{}:{}:%\n", 1234, 42, 313, "str", nullptr, 'X')); |
| 92 | + } |
| 93 | +}; |
| 94 | + |
| 95 | +#endif |
| 96 | + |
72 | 97 | // STL IO Streams
|
73 |
| -class STLStreamFormat : public StringBase |
| 98 | +class StreamFormat : public StringBase |
74 | 99 | {
|
75 | 100 | public:
|
76 | 101 | void format_with_floats() override
|
@@ -99,7 +124,10 @@ void run_format_test(std::string &&name)
|
99 | 124 | std::map<std::string, std::unique_ptr<StringBase>> formatters;
|
100 | 125 | #if !defined(FLY_PROFILE)
|
101 | 126 | formatters.emplace("{fmt}", std::make_unique<FmtFormat>());
|
102 |
| - formatters.emplace("STL IO Streams", std::make_unique<STLStreamFormat>()); |
| 127 | + formatters.emplace("std::stringstream", std::make_unique<StreamFormat>()); |
| 128 | +# if __has_include(<format>) |
| 129 | + formatters.emplace("std::format", std::make_unique<StdFormat>()); |
| 130 | +# endif |
103 | 131 | #endif
|
104 | 132 | formatters.emplace("libfly", std::make_unique<LibflyFormat>());
|
105 | 133 |
|
|
0 commit comments