[flang][runtime] Make defined formatted I/O process format elementally (#74150)
[llvm-project.git] / libcxx / benchmarks / formatted_size.bench.cpp
blobde67dae719a7e60ede2052bd45f53107f5a810eb
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
5 //
6 //===----------------------------------------------------------------------===//
8 #include <format>
10 #include <string>
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_formatted_size_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::formatted_size(CSTR("{}"), str));
25 state.SetBytesProcessed(state.iterations() * size * sizeof(CharT));
27 BENCHMARK_TEMPLATE(BM_formatted_size_string, char)->RangeMultiplier(2)->Range(1, 1 << 20);
28 BENCHMARK_TEMPLATE(BM_formatted_size_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))
33 return 1;
35 benchmark::RunSpecifiedBenchmarks();