Skip to content

Commit 7f89426

Browse files
committed
[benchmark] Restore running benchmarks by numbers
Reintroduced feature lost during `BenchmarkInfo` modernization: All registered benchmarks are ordered alphabetically and assigned an index. This number can be used as a shortcut to invoke the test instead of its full name. (Adding and removing tests from the suite will naturally reassign the indices, but they are stable for a given build.) The `--list` parameter now prints the test *number*, *name* and *tags* separated by delimiter. The `--list` output format is modified from: ```` Enabled Tests,Tags AngryPhonebook,[String, api, validation] ... ```` to this: ```` \#,Test,[Tags] 2,AngryPhonebook,[String, api, validation] … ```` (There isn’t a backslash before the #, git was eating the whole line without it.) Note: Test number 1 is Ackermann, which is marked as “skip”, so it’s not listed with the default `skip-tags` value. Fixes the issue where running tests via `Benchmark_Driver` always reported each test as number 1. Each test is run independently, therefore every invocation was “first”. Restoring test numbers resolves this issue back to original state: The number reported in the first column when executing the tests is its ordinal number in the Swift Benchmark Suite.
1 parent d82c996 commit 7f89426

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

benchmark/scripts/Benchmark_Driver

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,19 +127,19 @@ def get_tests(driver_path, args):
127127
driver.append('--delim=\t')
128128
if args.benchmarks or args.filters:
129129
driver.append('--skip-tags=') # list all tests, don't skip any tags
130-
names = [
131-
line.split('\t')[0] for line in
130+
index_name_pairs = [
131+
line.split('\t')[:2] for line in
132132
subprocess.check_output(driver).split('\n')[1:-1]
133133
]
134+
indices, names = zip(*index_name_pairs) # unzip list of pairs into 2 lists
134135
if args.filters:
135136
regexes = [re.compile(pattern) for pattern in args.filters]
136137
return sorted(list(set([name for pattern in regexes
137138
for name in names if pattern.match(name)])))
138139
if not args.benchmarks:
139140
return names
140141
benchmarks = set(args.benchmarks)
141-
indices = [str(i) for i in range(1, len(names) + 1)]
142-
index_to_name = dict(zip(indices, names))
142+
index_to_name = dict(index_name_pairs)
143143
indexed_names = [index_to_name[i]
144144
for i in benchmarks.intersection(set(indices))]
145145
return sorted(list(

benchmark/utils/DriverUtils.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,18 +228,21 @@ struct TestConfig {
228228

229229
mutating func findTestsToRun() {
230230
registeredBenchmarks.sort()
231-
let benchmarkNames = Set(filters)
231+
let indices = Dictionary(uniqueKeysWithValues:
232+
zip(registeredBenchmarks.map{$0.name}, 1...))
233+
let benchmarkNamesOrIndices = Set(filters)
232234
// needed so we don't capture an ivar of a mutable inout self.
233235
let (_tags, _skipTags) = (tags, skipTags)
234236

235237
tests = registeredBenchmarks.filter { benchmark in
236-
if benchmarkNames.isEmpty {
238+
if benchmarkNamesOrIndices.isEmpty {
237239
return benchmark.tags.isSuperset(of: _tags) &&
238240
benchmark.tags.isDisjoint(with: _skipTags)
239241
} else {
240-
return benchmarkNames.contains(benchmark.name)
242+
return benchmarkNamesOrIndices.contains(benchmark.name) ||
243+
benchmarkNamesOrIndices.contains(String(indices[benchmark.name]!))
241244
}
242-
}.enumerated().map { Test(benchInfo: $0.element, index: $0.offset + 1) }
245+
}.map { Test(benchInfo: $0, index: indices[$0.name]!) }
243246
}
244247
}
245248

@@ -478,9 +481,9 @@ public func main() {
478481
fatalError("\(msg)")
479482
case .listTests:
480483
config.findTestsToRun()
481-
print("Enabled Tests\(config.delim)Tags")
484+
print("#\(config.delim)Test\(config.delim)[Tags]")
482485
for t in config.tests {
483-
print("\(t.name)\(config.delim)\(t.tags)")
486+
print("\(t.index)\(config.delim)\(t.name)\(config.delim)\(t.tags)")
484487
}
485488
case .run:
486489
config.findTestsToRun()

test/benchmark/Benchmark_O.test-sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
// ORSKIPTAGS-NOT: RomanNumbers
4242

4343
// RUN: %Benchmark_O --list | %FileCheck %s --check-prefix LISTPRECOMMIT
44-
// LISTPRECOMMIT: Enabled Tests,Tags
44+
// LISTPRECOMMIT: #,Test,[Tags]
4545
// LISTPRECOMMIT-NOT: Ackermann
46-
// LISTPRECOMMIT: AngryPhonebook
46+
// LISTPRECOMMIT: {{[0-9]+}},AngryPhonebook
4747

4848
// RUN: %Benchmark_O --list --skip-tags= | %FileCheck %s --check-prefix LISTALL
4949
// LISTALL: Ackermann

0 commit comments

Comments
 (0)