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