Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/benchmark_register.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,26 @@ bool BenchmarkFamilies::FindBenchmarks(
benchmarks->reserve(benchmarks->size() + family_size);
}

// Optimization: Quick check if family name could match the filter
// before iterating through all args combinations
bool family_name_disabled = family->name_.rfind(kDisabledPrefix, 0) == 0;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why rfind() though, instead of find()?
That being said i think it might make sense to define a helper function string_has_prefix() for this...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No rfind now. let me know what you think of latest code.

bool family_could_match = false;

if (!family_name_disabled) {
// Check if the filter spec starts with the family name
// or if the family name appears as a substring in the spec
family_could_match = spec.find(family->name_) != std::string::npos ||
spec == "." ||
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The . special case should probably be checked first.

family->name_.find(spec) == 0; // spec is prefix of family name
}

// For positive filters, skip family if it can't possibly match
// For negative filters, we need to process all since we're excluding matches
if (!is_negative_filter && !family_could_match && spec != ".") {
// Skip this entire family - no instances will match
continue;
}

for (auto const& args : family->args_) {
for (int num_threads : *thread_counts) {
BenchmarkInstance instance(family.get(), family_index,
Expand Down
Loading