mirror of
https://github.com/google/benchmark.git
synced 2024-12-27 13:00:36 +08:00
Filter out benchmarks that start with "DISABLED_" (#1387)
* Filter out benchmarks that start with "DISABLED_" This could be slightly more elegant, in that the registration and the benchmark definition names have to change. Ideally, we'd still register without the DISABLED_ prefix and it would all "just work". Fixes #1365 * add some documentation
This commit is contained in:
parent
dc901ff909
commit
a162a38ca0
@ -182,6 +182,12 @@ BM_memcpy/32 12 ns 12 ns 54687500
|
||||
BM_memcpy/32k 1834 ns 1837 ns 357143
|
||||
```
|
||||
|
||||
## Disabling Benchmarks
|
||||
|
||||
It is possible to temporarily disable benchmarks by renaming the benchmark
|
||||
function to have the prefix "DISABLED_". This will cause the benchmark to
|
||||
be skipped at runtime.
|
||||
|
||||
<a name="result-comparison" />
|
||||
|
||||
## Result comparison
|
||||
|
@ -53,10 +53,13 @@ namespace benchmark {
|
||||
|
||||
namespace {
|
||||
// For non-dense Range, intermediate values are powers of kRangeMultiplier.
|
||||
static const int kRangeMultiplier = 8;
|
||||
static constexpr int kRangeMultiplier = 8;
|
||||
|
||||
// The size of a benchmark family determines is the number of inputs to repeat
|
||||
// the benchmark on. If this is "large" then warn the user during configuration.
|
||||
static const size_t kMaxFamilySize = 100;
|
||||
static constexpr size_t kMaxFamilySize = 100;
|
||||
|
||||
static constexpr char kDisabledPrefix[] = "DISABLED_";
|
||||
} // end namespace
|
||||
|
||||
namespace internal {
|
||||
@ -116,10 +119,10 @@ bool BenchmarkFamilies::FindBenchmarks(
|
||||
// Make regular expression out of command-line flag
|
||||
std::string error_msg;
|
||||
Regex re;
|
||||
bool isNegativeFilter = false;
|
||||
bool is_negative_filter = false;
|
||||
if (spec[0] == '-') {
|
||||
spec.replace(0, 1, "");
|
||||
isNegativeFilter = true;
|
||||
is_negative_filter = true;
|
||||
}
|
||||
if (!re.Init(spec, &error_msg)) {
|
||||
Err << "Could not compile benchmark re: " << error_msg << std::endl;
|
||||
@ -154,7 +157,8 @@ bool BenchmarkFamilies::FindBenchmarks(
|
||||
<< " will be repeated at least " << family_size << " times.\n";
|
||||
}
|
||||
// reserve in the special case the regex ".", since we know the final
|
||||
// family size.
|
||||
// family size. this doesn't take into account any disabled benchmarks
|
||||
// so worst case we reserve more than we need.
|
||||
if (spec == ".") benchmarks->reserve(benchmarks->size() + family_size);
|
||||
|
||||
for (auto const& args : family->args_) {
|
||||
@ -164,8 +168,9 @@ bool BenchmarkFamilies::FindBenchmarks(
|
||||
num_threads);
|
||||
|
||||
const auto full_name = instance.name().str();
|
||||
if ((re.Match(full_name) && !isNegativeFilter) ||
|
||||
(!re.Match(full_name) && isNegativeFilter)) {
|
||||
if (full_name.rfind(kDisabledPrefix, 0) != 0 &&
|
||||
((re.Match(full_name) && !is_negative_filter) ||
|
||||
(!re.Match(full_name) && is_negative_filter))) {
|
||||
benchmarks->push_back(std::move(instance));
|
||||
|
||||
++per_family_instance_index;
|
||||
|
@ -95,6 +95,18 @@ ADD_CASES({"test1", "One"}, {"test2", "Two"}, {"test3", "Three"});
|
||||
|
||||
#endif // BENCHMARK_HAS_NO_VARIADIC_REGISTER_BENCHMARK
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
// Test RegisterBenchmark with DISABLED_ benchmark
|
||||
//----------------------------------------------------------------------------//
|
||||
void DISABLED_BM_function(benchmark::State& state) {
|
||||
for (auto _ : state) {
|
||||
}
|
||||
}
|
||||
BENCHMARK(DISABLED_BM_function);
|
||||
ReturnVal dummy3 = benchmark::RegisterBenchmark("DISABLED_BM_function_manual",
|
||||
DISABLED_BM_function);
|
||||
// No need to add cases because we don't expect them to run.
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
// Test RegisterBenchmark with different callable types
|
||||
//----------------------------------------------------------------------------//
|
||||
|
Loading…
Reference in New Issue
Block a user