Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
libcxx/benchmarks/format_itoa_to_chars_base_10.bench.cpp
- This file was added.
//===----------------------------------------------------------------------===// | |||||
// 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 "FormatItoa.h" | |||||
#include <charconv> | |||||
template <class CharT, class T> | |||||
static void BM_to_chars_base_10(benchmark::State& state) { | |||||
std::array<T, batch_size> values = create_array<T>(state.range(0)); | |||||
char buffer[128]; | |||||
while (state.KeepRunningBatch(batch_size)) | |||||
for (auto value : values) | |||||
benchmark::DoNotOptimize(std::to_chars(buffer, &buffer[128], value)); | |||||
} | |||||
BENCHMARK_TEMPLATE(BM_to_chars_base_10, char, uint32_t) | |||||
->DenseRange(1, digits_max<uint32_t>, 1); | |||||
BENCHMARK_TEMPLATE(BM_to_chars_base_10, char, int32_t) | |||||
->DenseRange(1, digits_max<int32_t>, 1); | |||||
BENCHMARK_TEMPLATE(BM_to_chars_base_10, char, uint64_t) | |||||
->DenseRange(1, digits_max<uint64_t>, 1); | |||||
BENCHMARK_TEMPLATE(BM_to_chars_base_10, char, int64_t) | |||||
->DenseRange(1, digits_max<int64_t>, 1); | |||||
template <class CharT, class T> | |||||
static void BM_format_to_chars_base_10(benchmark::State& state) { | |||||
std::array<T, batch_size> values = create_array<T>(state.range(0)); | |||||
char buffer[128]; | |||||
while (state.KeepRunningBatch(batch_size)) | |||||
for (auto value : values) | |||||
benchmark::DoNotOptimize(std::__to_chars_base_10(buffer, value)); | |||||
} | |||||
BENCHMARK_TEMPLATE(BM_format_to_chars_base_10, char, uint32_t) | |||||
->DenseRange(1, digits_max<uint32_t>, 1); | |||||
BENCHMARK_TEMPLATE(BM_format_to_chars_base_10, char, int32_t) | |||||
->DenseRange(1, digits_max<int32_t>, 1); | |||||
BENCHMARK_TEMPLATE(BM_format_to_chars_base_10, char, uint64_t) | |||||
->DenseRange(1, digits_max<uint64_t>, 1); | |||||
BENCHMARK_TEMPLATE(BM_format_to_chars_base_10, char, int64_t) | |||||
->DenseRange(1, digits_max<int64_t>, 1); | |||||
#ifndef _LIBCPP_HAS_NO_INT128 | |||||
BENCHMARK_TEMPLATE(BM_format_to_chars_base_10, char, __uint128_t) | |||||
->DenseRange(1, digits_max<__uint128_t>, 1); | |||||
BENCHMARK_TEMPLATE(BM_format_to_chars_base_10, char, __int128_t) | |||||
->DenseRange(1, digits_max<__int128_t>, 1); | |||||
#endif | |||||
BENCHMARK_TEMPLATE(BM_format_to_chars_base_10, wchar_t, uint32_t) | |||||
->DenseRange(1, digits_max<uint32_t>, 1); | |||||
BENCHMARK_TEMPLATE(BM_format_to_chars_base_10, wchar_t, int32_t) | |||||
->DenseRange(1, digits_max<int32_t>, 1); | |||||
BENCHMARK_TEMPLATE(BM_format_to_chars_base_10, wchar_t, uint64_t) | |||||
->DenseRange(1, digits_max<uint64_t>, 1); | |||||
BENCHMARK_TEMPLATE(BM_format_to_chars_base_10, wchar_t, int64_t) | |||||
->DenseRange(1, digits_max<int64_t>, 1); | |||||
#ifndef _LIBCPP_HAS_NO_INT128 | |||||
BENCHMARK_TEMPLATE(BM_format_to_chars_base_10, wchar_t, __uint128_t) | |||||
->DenseRange(1, digits_max<__uint128_t>, 1); | |||||
BENCHMARK_TEMPLATE(BM_format_to_chars_base_10, wchar_t, __int128_t) | |||||
->DenseRange(1, digits_max<__int128_t>, 1); | |||||
#endif | |||||
#ifndef _LIBCPP_NO_HAS_CHAR8_T | |||||
BENCHMARK_TEMPLATE(BM_format_to_chars_base_10, char8_t, uint32_t) | |||||
->DenseRange(1, digits_max<uint32_t>, 1); | |||||
BENCHMARK_TEMPLATE(BM_format_to_chars_base_10, char8_t, int32_t) | |||||
->DenseRange(1, digits_max<int32_t>, 1); | |||||
BENCHMARK_TEMPLATE(BM_format_to_chars_base_10, char8_t, uint64_t) | |||||
->DenseRange(1, digits_max<uint64_t>, 1); | |||||
BENCHMARK_TEMPLATE(BM_format_to_chars_base_10, char8_t, int64_t) | |||||
->DenseRange(1, digits_max<int64_t>, 1); | |||||
#ifndef _LIBCPP_HAS_NO_INT128 | |||||
BENCHMARK_TEMPLATE(BM_format_to_chars_base_10, char8_t, __uint128_t) | |||||
->DenseRange(1, digits_max<__uint128_t>, 1); | |||||
BENCHMARK_TEMPLATE(BM_format_to_chars_base_10, char8_t, __int128_t) | |||||
->DenseRange(1, digits_max<__int128_t>, 1); | |||||
#endif | |||||
#endif | |||||
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS | |||||
BENCHMARK_TEMPLATE(BM_format_to_chars_base_10, char16_t, uint32_t) | |||||
->DenseRange(1, digits_max<uint32_t>, 1); | |||||
BENCHMARK_TEMPLATE(BM_format_to_chars_base_10, char16_t, int32_t) | |||||
->DenseRange(1, digits_max<int32_t>, 1); | |||||
BENCHMARK_TEMPLATE(BM_format_to_chars_base_10, char16_t, uint64_t) | |||||
->DenseRange(1, digits_max<uint64_t>, 1); | |||||
BENCHMARK_TEMPLATE(BM_format_to_chars_base_10, char16_t, int64_t) | |||||
->DenseRange(1, digits_max<int64_t>, 1); | |||||
#ifndef _LIBCPP_HAS_NO_INT128 | |||||
BENCHMARK_TEMPLATE(BM_format_to_chars_base_10, char16_t, __uint128_t) | |||||
->DenseRange(1, digits_max<__uint128_t>, 1); | |||||
BENCHMARK_TEMPLATE(BM_format_to_chars_base_10, char16_t, __int128_t) | |||||
->DenseRange(1, digits_max<__int128_t>, 1); | |||||
#endif | |||||
BENCHMARK_TEMPLATE(BM_format_to_chars_base_10, char32_t, uint32_t) | |||||
->DenseRange(1, digits_max<uint32_t>, 1); | |||||
BENCHMARK_TEMPLATE(BM_format_to_chars_base_10, char32_t, int32_t) | |||||
->DenseRange(1, digits_max<int32_t>, 1); | |||||
BENCHMARK_TEMPLATE(BM_format_to_chars_base_10, char32_t, uint64_t) | |||||
->DenseRange(1, digits_max<uint64_t>, 1); | |||||
BENCHMARK_TEMPLATE(BM_format_to_chars_base_10, char32_t, int64_t) | |||||
->DenseRange(1, digits_max<int64_t>, 1); | |||||
#ifndef _LIBCPP_HAS_NO_INT128 | |||||
BENCHMARK_TEMPLATE(BM_format_to_chars_base_10, char32_t, __uint128_t) | |||||
->DenseRange(1, digits_max<__uint128_t>, 1); | |||||
BENCHMARK_TEMPLATE(BM_format_to_chars_base_10, char32_t, __int128_t) | |||||
->DenseRange(1, digits_max<__int128_t>, 1); | |||||
#endif | |||||
#endif | |||||
int main(int argc, char** argv) { | |||||
benchmark::Initialize(&argc, argv); | |||||
if (benchmark::ReportUnrecognizedArguments(argc, argv)) | |||||
return 1; | |||||
benchmark::RunSpecifiedBenchmarks(); | |||||
} |