1 //===----------------------------------------------------------------------===//
2 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3 // See https://llvm.org/LICENSE.txt for license information.
4 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //===----------------------------------------------------------------------===//
12 #include "benchmark/benchmark.h"
13 #include "make_string.h"
15 #define CSTR(S) MAKE_CSTRING(CharT, S)
17 template <class CharT
>
18 static void BM_format_string(benchmark::State
& state
) {
19 size_t size
= state
.range(0);
20 std::basic_string
<CharT
> str(size
, CharT('*'));
22 while (state
.KeepRunningBatch(str
.size()))
23 benchmark::DoNotOptimize(std::format(CSTR("{}"), str
));
25 state
.SetBytesProcessed(state
.iterations() * size
* sizeof(CharT
));
27 BENCHMARK_TEMPLATE(BM_format_string
, char)->RangeMultiplier(2)->Range(1, 1 << 20);
28 BENCHMARK_TEMPLATE(BM_format_string
, wchar_t)->RangeMultiplier(2)->Range(1, 1 << 20);
30 int main(int argc
, char** argv
) {
31 benchmark::Initialize(&argc
, argv
);
32 if (benchmark::ReportUnrecognizedArguments(argc
, argv
))
35 benchmark::RunSpecifiedBenchmarks();