37 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++1710 11#include <format>12 13#include <string>14 15#include "benchmark/benchmark.h"16#include "make_string.h"17#include "test_macros.h"18 19#define CSTR(S) MAKE_CSTRING(CharT, S)20 21template <class CharT>22static void BM_formatted_size_string(benchmark::State& state) {23 size_t size = state.range(0);24 std::basic_string<CharT> str(size, CharT('*'));25 26 while (state.KeepRunningBatch(str.size()))27 benchmark::DoNotOptimize(std::formatted_size(CSTR("{}"), str));28 29 state.SetBytesProcessed(state.iterations() * size * sizeof(CharT));30}31BENCHMARK(BM_formatted_size_string<char>)->RangeMultiplier(2)->Range(1, 1 << 20);32#ifndef TEST_HAS_NO_WIDE_CHARACTERS33BENCHMARK(BM_formatted_size_string<wchar_t>)->RangeMultiplier(2)->Range(1, 1 << 20);34#endif35 36BENCHMARK_MAIN();37