cb66c5d68e
bazel / bazel.ubuntu-latest (push) Failing after 1s
build-and-test-perfcounters / ubuntu-latest.Debug (push) Failing after 0s
build-and-test-perfcounters / ubuntu-latest.Release (push) Failing after 1s
doxygen / Build HTML documentation (push) Failing after 1s
python + Bazel pre-commit checks / pre-commit (push) Failing after 1s
sanitizer / tsan.Debug (push) Failing after 1s
sanitizer / ubsan.Debug (push) Failing after 0s
sanitizer / ubsan.RelWithDebInfo (push) Failing after 1s
build-and-test-min-cmake / ubuntu-latest.min-cmake (push) Failing after 1s
clang-format-lint / check-clang-format (push) Failing after 1s
sanitizer / asan.Debug (push) Failing after 1s
sanitizer / msan.RelWithDebInfo (push) Failing after 1s
clang-tidy / run-clang-tidy (push) Failing after 1s
sanitizer / msan.Debug (push) Failing after 1s
sanitizer / asan.RelWithDebInfo (push) Failing after 0s
sanitizer / tsan.RelWithDebInfo (push) Failing after 0s
test-bindings / Test Rust bindings on ubuntu-latest (push) Failing after 0s
test-bindings / Test Python 3.10 bindings on ubuntu-latest (push) Failing after 0s
test-bindings / Test Python 3.11 bindings on ubuntu-latest (push) Failing after 0s
test-bindings / Test Python 3.12 bindings on ubuntu-latest (push) Failing after 1s
test-bindings / Test Python 3.13 bindings on ubuntu-latest (push) Failing after 0s
build-and-test / macos-latest.Debug.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Debug.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Debug.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Debug.shared.clang++ (push) Has been cancelled
bazel / bazel.macos-latest (push) Has been cancelled
bazel / bazel.windows-latest (push) Has been cancelled
build-and-test-min-cmake / macos-latest.min-cmake (push) Has been cancelled
build-and-test / ubuntu-22.04.Debug.static.clang++ (push) Has been cancelled
build-and-test / macos-latest.Debug.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Debug.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Debug.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Debug.shared.g++ (push) Has been cancelled
build-and-test / macos-latest.Debug.static.g++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Debug.static.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Debug.static.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Debug.static.g++ (push) Has been cancelled
build-and-test / macos-latest.Release.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Release.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Release.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Release.shared.clang++ (push) Has been cancelled
build-and-test / macos-latest.Release.static.clang++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Release.static.clang++ (push) Has been cancelled
build-and-test / macos-latest.Debug.static.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Debug.static.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Debug.static.clang++ (push) Has been cancelled
build-and-test / macos-latest.Release.static.g++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Release.static.g++ (push) Has been cancelled
build-and-test / windows-2025.Debug.static.VS-18-2025 (push) Has been cancelled
build-and-test / windows-2022.Release.shared.VS-17-2022 (push) Has been cancelled
build-and-test / windows-2022.Release.static.VS-17-2022 (push) Has been cancelled
build-and-test / windows-2025.Release.shared.VS-18-2025 (push) Has been cancelled
build-and-test / windows-2025.Release.static.VS-18-2025 (push) Has been cancelled
build-and-test / windows-latest.Debug.shared.CLANG64 (push) Has been cancelled
build-and-test / windows-latest.Debug.shared.MINGW64 (push) Has been cancelled
build-and-test / windows-latest.Debug.shared.UCRT64 (push) Has been cancelled
build-and-test / windows-latest.Debug.static.CLANG64 (push) Has been cancelled
build-and-test / windows-latest.Debug.static.MINGW64 (push) Has been cancelled
build-and-test / windows-latest.Debug.static.UCRT64 (push) Has been cancelled
build-and-test / ubuntu-24.04.Release.static.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Release.static.clang++ (push) Has been cancelled
build-and-test / macos-latest.Release.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Release.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Release.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Release.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Release.static.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Release.static.g++ (push) Has been cancelled
build-and-test / windows-2022.Debug.shared.VS-17-2022 (push) Has been cancelled
build-and-test / windows-2022.Debug.static.VS-17-2022 (push) Has been cancelled
build-and-test / windows-2025.Debug.shared.VS-18-2025 (push) Has been cancelled
build-and-test / windows-latest.Release.static.MINGW64 (push) Has been cancelled
build-and-test / windows-latest.Release.static.UCRT64 (push) Has been cancelled
test-bindings / Test Python 3.10 bindings on macos-latest (push) Has been cancelled
test-bindings / Test Python 3.11 bindings on macos-latest (push) Has been cancelled
test-bindings / Test Python 3.12 bindings on macos-latest (push) Has been cancelled
test-bindings / Test Python 3.13 bindings on macos-latest (push) Has been cancelled
build-and-test / windows-latest.Release.shared.CLANG64 (push) Has been cancelled
build-and-test / windows-latest.Release.shared.MINGW64 (push) Has been cancelled
build-and-test / windows-latest.Release.shared.UCRT64 (push) Has been cancelled
build-and-test / windows-latest.Release.static.CLANG64 (push) Has been cancelled
test-bindings / Test Python 3.12 bindings on windows-latest (push) Has been cancelled
test-bindings / Test Python 3.13 bindings on windows-latest (push) Has been cancelled
test-bindings / Test Python 3.10 bindings on windows-latest (push) Has been cancelled
test-bindings / Test Python 3.11 bindings on windows-latest (push) Has been cancelled
test-bindings / Test Rust bindings on macos-latest (push) Has been cancelled
test-bindings / Test Rust bindings on windows-latest (push) Has been cancelled
124 lines
3.3 KiB
C++
124 lines
3.3 KiB
C++
#include <cstdarg>
|
|
#include <set>
|
|
#include <string>
|
|
#include <vector>
|
|
#undef NDEBUG
|
|
|
|
#include "../src/commandlineflags.h"
|
|
#include "../src/perf_counters.h"
|
|
#include "benchmark/benchmark_api.h"
|
|
#include "benchmark/registration.h"
|
|
#include "benchmark/state.h"
|
|
#include "benchmark/utils.h"
|
|
#include "output_test.h"
|
|
|
|
namespace benchmark {
|
|
|
|
BM_DECLARE_string(benchmark_perf_counters);
|
|
|
|
} // namespace benchmark
|
|
namespace {
|
|
const char kGenericPerfEvent1[] = "CYCLES";
|
|
const char kGenericPerfEvent2[] = "INSTRUCTIONS";
|
|
|
|
std::set<std::string> UniqueCounterNames(
|
|
const benchmark::internal::PerfCounters& counters) {
|
|
return {counters.names().begin(), counters.names().end()};
|
|
}
|
|
|
|
bool HasRequiredPerfCounters(const std::vector<std::string>& names) {
|
|
if (!benchmark::internal::PerfCounters::kSupported) {
|
|
return false;
|
|
}
|
|
auto counters = benchmark::internal::PerfCounters::Create(names);
|
|
auto actual_names = UniqueCounterNames(counters);
|
|
for (const auto& name : names) {
|
|
if (actual_names.find(name) == actual_names.end()) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void BM_Simple(benchmark::State& state) {
|
|
for (auto _ : state) {
|
|
auto iterations = double(state.iterations()) * double(state.iterations());
|
|
benchmark::DoNotOptimize(iterations);
|
|
}
|
|
}
|
|
BENCHMARK(BM_Simple);
|
|
ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_Simple\",$"}});
|
|
|
|
const int kIters = 1000000;
|
|
|
|
void BM_WithoutPauseResume(benchmark::State& state) {
|
|
int n = 0;
|
|
|
|
for (auto _ : state) {
|
|
for (auto i = 0; i < kIters; ++i) {
|
|
n = 1 - n;
|
|
benchmark::DoNotOptimize(n);
|
|
}
|
|
}
|
|
}
|
|
|
|
BENCHMARK(BM_WithoutPauseResume);
|
|
ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_WithoutPauseResume\",$"}});
|
|
|
|
void BM_WithPauseResume(benchmark::State& state) {
|
|
int m = 0, n = 0;
|
|
|
|
for (auto _ : state) {
|
|
for (auto i = 0; i < kIters; ++i) {
|
|
n = 1 - n;
|
|
benchmark::DoNotOptimize(n);
|
|
}
|
|
|
|
state.PauseTiming();
|
|
for (auto j = 0; j < kIters; ++j) {
|
|
m = 1 - m;
|
|
benchmark::DoNotOptimize(m);
|
|
}
|
|
state.ResumeTiming();
|
|
}
|
|
}
|
|
|
|
BENCHMARK(BM_WithPauseResume);
|
|
|
|
ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_WithPauseResume\",$"}});
|
|
|
|
static void CheckSimple(Results const& e) {
|
|
CHECK_COUNTER_VALUE(e, double, kGenericPerfEvent1, GT, 0);
|
|
}
|
|
|
|
double withoutPauseResumeInstrCount = 0.0;
|
|
double withPauseResumeInstrCount = 0.0;
|
|
|
|
void SaveInstrCountWithoutResume(Results const& e) {
|
|
withoutPauseResumeInstrCount = e.GetAs<double>(kGenericPerfEvent2);
|
|
}
|
|
|
|
void SaveInstrCountWithResume(Results const& e) {
|
|
withPauseResumeInstrCount = e.GetAs<double>(kGenericPerfEvent2);
|
|
}
|
|
|
|
CHECK_BENCHMARK_RESULTS("BM_Simple", &CheckSimple);
|
|
CHECK_BENCHMARK_RESULTS("BM_WithoutPauseResume", &SaveInstrCountWithoutResume);
|
|
CHECK_BENCHMARK_RESULTS("BM_WithPauseResume", &SaveInstrCountWithResume);
|
|
} // end namespace
|
|
|
|
int main(int argc, char* argv[]) {
|
|
benchmark::MaybeReenterWithoutASLR(argc, argv);
|
|
if (!HasRequiredPerfCounters({kGenericPerfEvent1, kGenericPerfEvent2})) {
|
|
return 0;
|
|
}
|
|
benchmark::FLAGS_benchmark_perf_counters =
|
|
std::string(kGenericPerfEvent1) + "," + kGenericPerfEvent2;
|
|
benchmark::internal::PerfCounters::Initialize();
|
|
RunOutputTests(argc, argv);
|
|
|
|
BM_CHECK_GT(withPauseResumeInstrCount, kIters);
|
|
BM_CHECK_GT(withoutPauseResumeInstrCount, kIters);
|
|
BM_CHECK_LT(withPauseResumeInstrCount, 1.5 * withoutPauseResumeInstrCount);
|
|
}
|