Files
clang-p2996/libcxx/test/benchmarks/format.bench.cpp
Mark de Wever d54b1cfa38 [libc++][format][1/3] Adds more benchmarks. (#101803)
This patch is the start of a series to improve the speed of std::format,
std::format_to, std::format_to_n, and std::formatted_size.

This is mostly achieved by changing the __output_buffer class. This new
__output_buffer class also makes it easier to implement buffering for
P3107R5 "Permit an efficient implementation of std::print"
2024-10-06 18:18:57 +02:00

34 lines
1.0 KiB
C++

//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include <format>
#include <string>
#include "benchmark/benchmark.h"
#include "make_string.h"
#define CSTR(S) MAKE_CSTRING(CharT, S)
template <class CharT>
static void BM_format_string(benchmark::State& state) {
size_t size = state.range(0);
std::basic_string<CharT> str(size, CharT('*'));
while (state.KeepRunningBatch(str.size())) {
std::basic_string<CharT> s = std::format(CSTR("{}"), str);
benchmark::DoNotOptimize(s);
}
state.SetBytesProcessed(state.iterations() * size * sizeof(CharT));
}
BENCHMARK(BM_format_string<char>)->RangeMultiplier(2)->Range(1, 1 << 20);
BENCHMARK(BM_format_string<wchar_t>)->RangeMultiplier(2)->Range(1, 1 << 20);
BENCHMARK_MAIN();