Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / benchmarks / format.bench.cpp
blob267ef22950668589e904cc869b42747b070139dc
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-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
11 #include <format>
13 #include <string>
15 #include "benchmark/benchmark.h"
16 #include "make_string.h"
17 #include "test_macros.h"
19 #define CSTR(S) MAKE_CSTRING(CharT, S)
21 template <class CharT>
22 static void BM_format_string(benchmark::State& state) {
23 size_t size = state.range(0);
24 std::basic_string<CharT> str(size, CharT('*'));
26 while (state.KeepRunningBatch(str.size())) {
27 std::basic_string<CharT> s = std::format(CSTR("{}"), str);
28 benchmark::DoNotOptimize(s);
31 state.SetBytesProcessed(state.iterations() * size * sizeof(CharT));
33 BENCHMARK(BM_format_string<char>)->RangeMultiplier(2)->Range(1, 1 << 20);
34 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
35 BENCHMARK(BM_format_string<wchar_t>)->RangeMultiplier(2)->Range(1, 1 << 20);
36 #endif
38 BENCHMARK_MAIN();