Skip to content

Commit

Permalink
Add bm_file_regex command line option to benchmark
Browse files Browse the repository at this point in the history
Summary:
Benchmarks already support --bm_regex to filter benchmarks by name.  This commit adds --bm_file_regex to further filter benchmarks by filename.

This is convenient when iterating on benchmarks for a single class which are typically placed in a single translation unit.

Reviewed By: Gownta

Differential Revision: D63044678

fbshipit-source-id: 648514fd3075859ab0cbfbdffd2bee48c37852c7
  • Loading branch information
Adrian Stone authored and facebook-github-bot committed Sep 26, 2024
1 parent 8fc0e33 commit ece5095
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion folly/Benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ FOLLY_GFLAGS_DEFINE_string(
FOLLY_GFLAGS_DEFINE_string(
bm_regex, "", "Only benchmarks whose names match this regex will be run.");

FOLLY_GFLAGS_DEFINE_string(
bm_file_regex,
"",
"Only benchmarks whose filenames match this regex will be run.");

FOLLY_GFLAGS_DEFINE_int64(
bm_min_usec,
100,
Expand Down Expand Up @@ -687,13 +692,18 @@ BenchmarksToRun selectBenchmarksToRun(
BenchmarksToRun res;

folly::Optional<boost::regex> bmRegex;
folly::Optional<boost::regex> bmFileRegex;

res.benchmarks.reserve(benchmarks.size());

if (!FLAGS_bm_regex.empty()) {
bmRegex.emplace(FLAGS_bm_regex);
}

if (!FLAGS_bm_file_regex.empty()) {
bmFileRegex.emplace(FLAGS_bm_file_regex);
}

for (auto& bm : benchmarks) {
if (bm.name == "-") {
addSeparator(res);
Expand All @@ -705,7 +715,11 @@ BenchmarksToRun selectBenchmarksToRun(
continue;
}

if (!bmRegex || boost::regex_search(bm.name, *bmRegex)) {
bool matchedName = !bmRegex || boost::regex_search(bm.name, *bmRegex);
bool matchedFile =
!bmFileRegex || boost::regex_search(bm.file, *bmFileRegex);

if (matchedName && matchedFile) {
res.benchmarks.push_back(&bm);
}
}
Expand Down

0 comments on commit ece5095

Please sign in to comment.