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
82 lines
2.8 KiB
C++
82 lines
2.8 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
|
|
|
|
#include "benchmark/benchmark.h"
|
|
#include <bitset>
|
|
#include <cmath>
|
|
#include <cstddef>
|
|
#include <random>
|
|
|
|
template <std::size_t N>
|
|
struct GenerateBitset {
|
|
// Construct a bitset with N bits, where each bit is set with probability p.
|
|
static std::bitset<N> generate(double p) {
|
|
std::bitset<N> b;
|
|
if (p <= 0.0)
|
|
return b;
|
|
if (p >= 1.0)
|
|
return ~b;
|
|
|
|
std::random_device rd;
|
|
std::mt19937 gen(rd());
|
|
std::bernoulli_distribution d(p);
|
|
for (std::size_t i = 0; i < N; ++i)
|
|
b[i] = d(gen);
|
|
|
|
return b;
|
|
}
|
|
|
|
static std::bitset<N> sparse() { return generate(0.1); }
|
|
static std::bitset<N> dense() { return generate(0.9); }
|
|
static std::bitset<N> uniform() { return generate(0.5); }
|
|
};
|
|
|
|
template <std::size_t N>
|
|
static void BM_BitsetToString(benchmark::State& state) {
|
|
double p = state.range(0) / 100.0;
|
|
std::bitset<N> b = GenerateBitset<N>::generate(p);
|
|
benchmark::DoNotOptimize(b);
|
|
|
|
for (auto _ : state) {
|
|
benchmark::DoNotOptimize(b.to_string());
|
|
}
|
|
}
|
|
|
|
// Sparse bitset
|
|
BENCHMARK(BM_BitsetToString<32>)->Arg(10)->Name("BM_BitsetToString<32>/Sparse (10%)");
|
|
BENCHMARK(BM_BitsetToString<64>)->Arg(10)->Name("BM_BitsetToString<64>/Sparse (10%)");
|
|
BENCHMARK(BM_BitsetToString<8192>)->Arg(10)->Name("BM_BitsetToString<8192>/Sparse (10%)");
|
|
BENCHMARK(BM_BitsetToString<1048576>)->Arg(10)->Name("BM_BitsetToString<1048576>/Sparse (10%)"); // 1 << 20
|
|
|
|
// Dense bitset
|
|
BENCHMARK(BM_BitsetToString<32>)->Arg(90)->Name("BM_BitsetToString<32>/Dense (90%)");
|
|
BENCHMARK(BM_BitsetToString<64>)->Arg(90)->Name("BM_BitsetToString<64>/Dense (90%)");
|
|
BENCHMARK(BM_BitsetToString<8192>)->Arg(90)->Name("BM_BitsetToString<8192>/Dense (90%)");
|
|
BENCHMARK(BM_BitsetToString<1048576>)->Arg(90)->Name("BM_BitsetToString<1048576>/Dense (90%)"); // 1 << 20
|
|
|
|
// Uniform bitset
|
|
BENCHMARK(BM_BitsetToString<32>)->Arg(50)->Name("BM_BitsetToString<32>/Uniform (50%)");
|
|
BENCHMARK(BM_BitsetToString<64>)->Arg(50)->Name("BM_BitsetToString<64>/Uniform (50%)");
|
|
BENCHMARK(BM_BitsetToString<8192>)->Arg(50)->Name("BM_BitsetToString<8192>/Uniform (50%)");
|
|
BENCHMARK(BM_BitsetToString<1048576>)->Arg(50)->Name("BM_BitsetToString<1048576>/Uniform (50%)"); // 1 << 20
|
|
|
|
static void BM_Bitset_ctor_ull(benchmark::State& state) {
|
|
unsigned long long val = 1;
|
|
for (auto _ : state) {
|
|
benchmark::DoNotOptimize(val);
|
|
std::bitset<128> b(val);
|
|
benchmark::DoNotOptimize(b);
|
|
}
|
|
}
|
|
|
|
BENCHMARK(BM_Bitset_ctor_ull);
|
|
|
|
BENCHMARK_MAIN();
|