Files
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

98 lines
2.6 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
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14
#include "benchmark/benchmark.h"
#include "test_macros.h"
#include <mutex>
#include <sstream>
TEST_NOINLINE double istream_numbers();
double istream_numbers(std::locale* loc) {
const char* a[] = {"-6 69 -71 2.4882e-02 -100 101 -2.00005 5000000 -50000000",
"-25 71 7 -9.3262e+01 -100 101 -2.00005 5000000 -50000000",
"-14 53 46 -6.7026e-02 -100 101 -2.00005 5000000 -50000000"};
int a1, a2, a3, a4, a5, a6, a7;
double f1 = 0.0, f2 = 0.0, q = 0.0;
for (int i = 0; i < 3; i++) {
std::istringstream s(a[i]);
if (loc)
s.imbue(*loc);
s >> a1 >> a2 >> a3 >> f1 >> a4 >> a5 >> f2 >> a6 >> a7;
q += (a1 + a2 + a3 + a4 + a5 + a6 + a7 + f1 + f2) / 1000000;
}
return q;
}
struct LocaleSelector {
std::locale* imbue;
std::locale old;
static std::mutex mutex;
LocaleSelector(benchmark::State& state) {
std::lock_guard guard(mutex);
switch (state.range(0)) {
case 0: {
old = std::locale::global(std::locale::classic());
imbue = nullptr;
break;
}
case 1: {
old = std::locale::global(std::locale::classic());
thread_local std::locale loc("en_US.UTF-8");
imbue = &loc;
break;
}
case 2: {
old = std::locale::global(std::locale::classic());
static std::locale loc("en_US.UTF-8");
imbue = &loc;
break;
}
case 3: {
old = std::locale::global(std::locale("en_US.UTF-8"));
imbue = nullptr;
break;
}
}
}
~LocaleSelector() {
std::lock_guard guard(mutex);
std::locale::global(old);
}
};
std::mutex LocaleSelector::mutex;
static void BM_Istream_numbers(benchmark::State& state) {
LocaleSelector sel(state);
double i = 0;
while (state.KeepRunning())
benchmark::DoNotOptimize(i += istream_numbers(sel.imbue));
}
BENCHMARK(BM_Istream_numbers)->DenseRange(0, 3);
static void BM_Ostream_number(benchmark::State& state) {
LocaleSelector sel(state);
while (state.KeepRunning()) {
std::ostringstream ss;
if (sel.imbue)
ss.imbue(*sel.imbue);
ss << 0;
benchmark::DoNotOptimize(ss.str().c_str());
}
}
BENCHMARK(BM_Ostream_number)->DenseRange(0, 3);
BENCHMARK_MAIN();