@@ -7,6 +7,8 @@ import TSCBasic
7
7
import TSCUtility
8
8
9
9
class CleanBuildPerformanceTests : XCTestCase {
10
+ enum WhatToMeasure { case reading, writing }
11
+
10
12
/// Test the cost of reading `swiftdeps` files without doing a full build. Use the files in "TestInputs/SampleSwiftDeps"
11
13
///
12
14
/// When doing an incremental but clean build, after every file is compiled, its `swiftdeps` file must be
@@ -20,6 +22,15 @@ class CleanBuildPerformanceTests: XCTestCase {
20
22
/// `cd` to the package directory, then:
21
23
/// `rm TestInputs/SampleSwiftDeps/*; rm -rf .build; swift build; find .build -name \*.swiftdeps -a -exec cp \{\} TestInputs/SampleSwiftDeps \;`
22
24
func testCleanBuildSwiftDepsPerformance( ) throws {
25
+ try testCleanBuildPerformance ( . reading)
26
+ }
27
+ func testCleanBuildSavingPriorsPerformance( ) throws {
28
+ try testCleanBuildPerformance ( . writing)
29
+ }
30
+
31
+
32
+ func testCleanBuildPerformance( _ whatToMeasure: WhatToMeasure ) throws {
33
+
23
34
#if !os(macOS)
24
35
// rdar://81411914
25
36
throw XCTSkip ( )
@@ -37,7 +48,7 @@ class CleanBuildPerformanceTests: XCTestCase {
37
48
let limit = 100 // This is the real test, optimized code.
38
49
#endif
39
50
40
- try test ( swiftDepsDirectory: swiftDepsDirectoryPath. pathString, atMost: limit)
51
+ try test ( swiftDepsDirectory: swiftDepsDirectoryPath. pathString, atMost: limit, whatToMeasure )
41
52
}
42
53
43
54
/// Test the cost of reading `swiftdeps` files without doing a full build.
@@ -49,13 +60,24 @@ class CleanBuildPerformanceTests: XCTestCase {
49
60
/// - Parameters:
50
61
/// - swiftDepsDirectory: where the swiftdeps files are, either absolute, or relative to the current directory
51
62
/// - limit: the maximum number of swiftdeps files to process.
52
- func test( swiftDepsDirectory: String , atMost limit: Int = . max) throws {
63
+ func test( swiftDepsDirectory: String , atMost limit: Int = . max, _ whatToMeasure : WhatToMeasure ) throws {
53
64
let ( outputFileMap, inputs) = try createOFMAndInputs ( swiftDepsDirectory, atMost: limit)
54
65
55
66
let info = IncrementalCompilationState . IncrementalDependencyAndInputSetup
56
67
. mock ( options: [ ] , outputFileMap: outputFileMap)
57
68
let g = ModuleDependencyGraph ( info, . updatingAfterCompilation)
58
- measure { readSwiftDeps ( for: inputs, into: g) }
69
+ switch whatToMeasure {
70
+ case . reading:
71
+ measure { readSwiftDeps ( for: inputs, into: g) }
72
+ case . writing:
73
+ readSwiftDeps ( for: inputs, into: g)
74
+ measure {
75
+ ModuleDependencyGraph . Serializer. serialize (
76
+ g,
77
+ " mock compiler version " ,
78
+ ModuleDependencyGraph . serializedGraphVersion)
79
+ }
80
+ }
59
81
}
60
82
61
83
/// Build the `OutputFileMap` and input vector for ``testCleanBuildSwiftDepsPerformance(_, atMost)``
0 commit comments