llvm-project
36 строк · 1.2 Кб
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//===----------------------------------------------------------------------===//
7
8#include <format>
9
10#include <string>
11
12#include "benchmark/benchmark.h"
13#include "make_string.h"
14
15#define CSTR(S) MAKE_CSTRING(CharT, S)
16
17template <class CharT>
18static void BM_formatted_size_string(benchmark::State& state) {
19size_t size = state.range(0);
20std::basic_string<CharT> str(size, CharT('*'));
21
22while (state.KeepRunningBatch(str.size()))
23benchmark::DoNotOptimize(std::formatted_size(CSTR("{}"), str));
24
25state.SetBytesProcessed(state.iterations() * size * sizeof(CharT));
26}
27BENCHMARK_TEMPLATE(BM_formatted_size_string, char)->RangeMultiplier(2)->Range(1, 1 << 20);
28BENCHMARK_TEMPLATE(BM_formatted_size_string, wchar_t)->RangeMultiplier(2)->Range(1, 1 << 20);
29
30int main(int argc, char** argv) {
31benchmark::Initialize(&argc, argv);
32if (benchmark::ReportUnrecognizedArguments(argc, argv))
33return 1;
34
35benchmark::RunSpecifiedBenchmarks();
36}
37