Skip to content

Commit b042215

Browse files
authored
Merge pull request #18211 from palimondo/fluctuation-of-the-pupil
[benchmark] Alphabetic sorting of tests and warning about incorrect use of memory option
2 parents 44cccd0 + 1a382ab commit b042215

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

benchmark/utils/DriverUtils.swift

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,16 @@ struct TestConfig {
141141
tags: c.tags ?? [],
142142
skipTags: c.skipTags ?? [.unstable, .skip])
143143

144+
if logMemory && tests.count > 1 {
145+
print(
146+
"""
147+
warning: The memory usage of a test, reported as the change in MAX_RSS,
148+
is based on measuring the peak memory used by the whole process.
149+
These results are meaningful only when running a single test,
150+
not in the batch mode!
151+
""")
152+
}
153+
144154
if verbose {
145155
let testList = tests.map({ $0.1.name }).joined(separator: ", ")
146156
print("""
@@ -174,8 +184,9 @@ struct TestConfig {
174184
tags: Set<BenchmarkCategory>,
175185
skipTags: Set<BenchmarkCategory>
176186
) -> [(index: String, info: BenchmarkInfo)] {
187+
let allTests = registeredBenchmarks.sorted()
177188
let indices = Dictionary(uniqueKeysWithValues:
178-
zip(registeredBenchmarks.sorted().map { $0.name },
189+
zip(allTests.map { $0.name },
179190
(1...).lazy.map { String($0) } ))
180191

181192
func byTags(b: BenchmarkInfo) -> Bool {
@@ -185,8 +196,8 @@ struct TestConfig {
185196
func byNamesOrIndices(b: BenchmarkInfo) -> Bool {
186197
return specifiedTests.contains(b.name) ||
187198
specifiedTests.contains(indices[b.name]!)
188-
} // !! "All registeredBenchmarks have been assigned an index"
189-
return registeredBenchmarks
199+
} // !! "`allTests` have been assigned an index"
200+
return allTests
190201
.filter(specifiedTests.isEmpty ? byTags : byNamesOrIndices)
191202
.map { (index: indices[$0.name]!, info: $0) }
192203
}

test/benchmark/Benchmark_O.test.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,19 @@ ORSKIPTAGS: Fibonacci
8686
ORSKIPTAGS-NOT: RomanNumbers
8787
````
8888

89+
Alphabetic sorting of tests
90+
91+
````
92+
RUN: %Benchmark_O --list \
93+
RUN: | %FileCheck %s --check-prefix ALPHASORT
94+
ALPHASORT: COWArrayGuaranteedParameterOverhead
95+
ALPHASORT: COWTree
96+
ALPHASORT: ChainedFilterMap
97+
ALPHASORT: Chars
98+
ALPHASORT: FatCompactMap
99+
100+
````
101+
89102
## Running Benchmarks
90103
Each real benchmark execution takes about a second per sample. If possible,
91104
multiple checks are combined into one run to minimize the test time.
@@ -175,6 +188,14 @@ BADSKIPTAG: error: 'bogus' is not a valid 'BenchmarkCategory'
175188
176189
````
177190

191+
Measuring memory use of a test with our method is valid only for single test.
192+
193+
````
194+
RUN: %Benchmark_O 1 2 --memory --list \
195+
RUN: 2>&1 | %FileCheck %s --check-prefix WARNMEMORY
196+
WARNMEMORY: warning:
197+
````
198+
178199
## Usage
179200

180201
````

0 commit comments

Comments
 (0)