mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-28 07:46:07 +00:00

Instead of building the benchmarks separately via CMake and running them separately from the test suite, this patch merges the benchmarks into the test suite and handles both uniformly. As a result: - It is now possible to run individual benchmarks like we run tests (e.g. using libcxx-lit), which is a huge quality-of-life improvement. - The benchmarks will be run under exactly the same configuration as the rest of the tests, which is a nice simplification. This does mean that one has to be careful to enable the desired optimization flags when running benchmarks, but that is easy with e.g. `libcxx-lit <...> --param optimization=speed`. - Benchmarks can use the same annotations as the rest of the test suite, such as `// UNSUPPORTED` & friends. When running the tests via `check-cxx`, we only compile the benchmarks because running them would be too time consuming. This introduces a bit of complexity in the testing setup, and instead it would be better to allow passing a --dry-run flag to GoogleBenchmark executables, which is the topic of https://github.com/google/benchmark/issues/1827. I am not really satisfied with the layering violation of adding the %{benchmark_flags} substitution to cmake-bridge, however I believe this can be improved in the future.
44 lines
1.2 KiB
C++
44 lines
1.2 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 <memory>
|
|
|
|
#include "benchmark/benchmark.h"
|
|
|
|
static void BM_SharedPtrCreateDestroy(benchmark::State& st) {
|
|
while (st.KeepRunning()) {
|
|
auto sp = std::make_shared<int>(42);
|
|
benchmark::DoNotOptimize(sp.get());
|
|
}
|
|
}
|
|
BENCHMARK(BM_SharedPtrCreateDestroy);
|
|
|
|
static void BM_SharedPtrIncDecRef(benchmark::State& st) {
|
|
auto sp = std::make_shared<int>(42);
|
|
benchmark::DoNotOptimize(sp.get());
|
|
while (st.KeepRunning()) {
|
|
std::shared_ptr<int> sp2(sp);
|
|
benchmark::ClobberMemory();
|
|
}
|
|
}
|
|
BENCHMARK(BM_SharedPtrIncDecRef);
|
|
|
|
static void BM_WeakPtrIncDecRef(benchmark::State& st) {
|
|
auto sp = std::make_shared<int>(42);
|
|
benchmark::DoNotOptimize(sp.get());
|
|
while (st.KeepRunning()) {
|
|
std::weak_ptr<int> wp(sp);
|
|
benchmark::ClobberMemory();
|
|
}
|
|
}
|
|
BENCHMARK(BM_WeakPtrIncDecRef);
|
|
|
|
BENCHMARK_MAIN();
|