@@ -6,7 +6,9 @@ extension BenchmarkRunner {
6
6
let url = URL ( fileURLWithPath: savePath, isDirectory: false )
7
7
let parent = url. deletingLastPathComponent ( )
8
8
if !FileManager. default. fileExists ( atPath: parent. path) {
9
- try ! FileManager . default. createDirectory ( atPath: parent. path, withIntermediateDirectories: true )
9
+ try ! FileManager . default. createDirectory (
10
+ atPath: parent. path,
11
+ withIntermediateDirectories: true )
10
12
}
11
13
print ( " Saving result to \( url. path) " )
12
14
try results. save ( to: url)
@@ -21,7 +23,11 @@ extension BenchmarkRunner {
21
23
}
22
24
23
25
/// Compare this runner's results against the results stored in the given file path
24
- func compare( against compareFilePath: String , showChart: Bool , saveTo: String ? ) throws {
26
+ func compare(
27
+ against compareFilePath: String ,
28
+ showChart: Bool ,
29
+ saveTo: String ?
30
+ ) throws {
25
31
let compareFileURL = URL ( fileURLWithPath: compareFilePath)
26
32
let compareResult = try SuiteResult . load ( from: compareFileURL)
27
33
let compareFile = compareFileURL. lastPathComponent
@@ -30,13 +36,22 @@ extension BenchmarkRunner {
30
36
. compare ( with: compareResult)
31
37
. filter ( { !$0. name. contains ( " _NS " ) } )
32
38
. filter ( { $0. diff != nil } )
33
- displayComparisons ( comparisons, showChart, against: " saved benchmark result " + compareFile)
39
+ displayComparisons (
40
+ comparisons,
41
+ showChart,
42
+ against: " saved benchmark result " + compareFile)
34
43
if let saveFile = saveTo {
35
44
try saveComparisons ( comparisons, path: saveFile)
36
45
}
37
46
}
38
47
39
- func compareCompileTimes( against compareFilePath: String , showChart: Bool ) throws {
48
+ // Compile times are often very short (5-20µs) so results are likely to be
49
+ // very affected by background tasks. This is primarily for making sure
50
+ // there aren't any catastrophic changes in compile times
51
+ func compareCompileTimes(
52
+ against compareFilePath: String ,
53
+ showChart: Bool
54
+ ) throws {
40
55
let compareFileURL = URL ( fileURLWithPath: compareFilePath)
41
56
let compareResult = try SuiteResult . load ( from: compareFileURL)
42
57
let compareFile = compareFileURL. lastPathComponent
@@ -45,20 +60,30 @@ extension BenchmarkRunner {
45
60
. compareCompileTimes ( with: compareResult)
46
61
. filter ( { !$0. name. contains ( " _NS " ) } )
47
62
. filter ( { $0. diff != nil } )
48
- print ( " [Experimental] Comparing estimated compile times " )
49
- displayComparisons ( compileTimeComparisons, false , against: " saved benchmark result " + compareFile)
63
+ print ( " Comparing estimated compile times " )
64
+ displayComparisons (
65
+ compileTimeComparisons,
66
+ false ,
67
+ against: " saved benchmark result " + compareFile)
50
68
}
51
69
52
70
/// Compares Swift Regex benchmark results against NSRegularExpression
53
71
func compareWithNS( showChart: Bool , saveTo: String ? ) throws {
54
72
let comparisons = results. compareWithNS ( ) . filter ( { $0. diff != nil } )
55
- displayComparisons ( comparisons, showChart, against: " NSRegularExpression (via CrossBenchmark) " )
73
+ displayComparisons (
74
+ comparisons,
75
+ showChart,
76
+ against: " NSRegularExpression (via CrossBenchmark) " )
56
77
if let saveFile = saveTo {
57
78
try saveComparisons ( comparisons, path: saveFile)
58
79
}
59
80
}
60
81
61
- func displayComparisons( _ comparisons: [ BenchmarkResult . Comparison ] , _ showChart: Bool , against: String ) {
82
+ func displayComparisons(
83
+ _ comparisons: [ BenchmarkResult . Comparison ] ,
84
+ _ showChart: Bool ,
85
+ against: String
86
+ ) {
62
87
let regressions = comparisons. filter ( { $0. diff!. seconds > 0 } )
63
88
. sorted ( by: { ( a, b) in a. diff!. seconds > b. diff!. seconds} )
64
89
let improvements = comparisons. filter ( { $0. diff!. seconds < 0 } )
@@ -95,11 +120,16 @@ extension BenchmarkRunner {
95
120
#endif
96
121
}
97
122
98
- func saveComparisons( _ comparisons: [ BenchmarkResult . Comparison ] , path: String ) throws {
123
+ func saveComparisons(
124
+ _ comparisons: [ BenchmarkResult . Comparison ] ,
125
+ path: String
126
+ ) throws {
99
127
let url = URL ( fileURLWithPath: path, isDirectory: false )
100
128
let parent = url. deletingLastPathComponent ( )
101
129
if !FileManager. default. fileExists ( atPath: parent. path) {
102
- try ! FileManager . default. createDirectory ( atPath: parent. path, withIntermediateDirectories: true )
130
+ try ! FileManager . default. createDirectory (
131
+ atPath: parent. path,
132
+ withIntermediateDirectories: true )
103
133
}
104
134
105
135
var contents = " name,latest,baseline,diff,percentage \n "
@@ -112,17 +142,10 @@ extension BenchmarkRunner {
112
142
}
113
143
114
144
struct BenchmarkResult : Codable {
145
+ let compileTime : Time
115
146
let median : Time
116
- let estimatedCompileTime : Time
117
147
let stdev : Double
118
148
let samples : Int
119
-
120
- init ( _ initialRunTime: Time , _ median: Time , _ stdev: Double , _ samples: Int ) {
121
- self . estimatedCompileTime = initialRunTime - median
122
- self . median = median
123
- self . stdev = stdev
124
- self . samples = samples
125
- }
126
149
}
127
150
128
151
extension BenchmarkResult {
@@ -135,7 +158,7 @@ extension BenchmarkResult {
135
158
136
159
var diff : Time ? {
137
160
if diffCompileTimes {
138
- return latest. estimatedCompileTime - baseline. estimatedCompileTime
161
+ return latest. compileTime - baseline. compileTime
139
162
}
140
163
if Stats . tTest ( baseline, latest) {
141
164
return latest. median - baseline. median
@@ -150,8 +173,8 @@ extension BenchmarkResult {
150
173
let oldVal : Time
151
174
let newVal : Time
152
175
if diffCompileTimes {
153
- oldVal = baseline. estimatedCompileTime
154
- newVal = latest. estimatedCompileTime
176
+ oldVal = baseline. compileTime
177
+ newVal = latest. compileTime
155
178
} else {
156
179
oldVal = baseline. median
157
180
newVal = latest. median
@@ -169,8 +192,8 @@ extension BenchmarkResult {
169
192
let oldVal : Time
170
193
let newVal : Time
171
194
if diffCompileTimes {
172
- oldVal = baseline. estimatedCompileTime
173
- newVal = latest. estimatedCompileTime
195
+ oldVal = baseline. compileTime
196
+ newVal = latest. compileTime
174
197
} else {
175
198
oldVal = baseline. median
176
199
newVal = latest. median
@@ -213,13 +236,18 @@ struct SuiteResult {
213
236
return comparisons
214
237
}
215
238
216
- /// Compares the estimated compile times
217
- func compareCompileTimes( with other: SuiteResult ) -> [ BenchmarkResult . Comparison ] {
239
+ /// Compares the compile times
240
+ func compareCompileTimes(
241
+ with other: SuiteResult
242
+ ) -> [ BenchmarkResult . Comparison ] {
218
243
var comparisons : [ BenchmarkResult . Comparison ] = [ ]
219
244
for item in results {
220
245
if let otherVal = other. results [ item. key] {
221
246
comparisons. append (
222
- . init( name: item. key, baseline: otherVal, latest: item. value, diffCompileTimes: true ) )
247
+ . init( name: item. key,
248
+ baseline: otherVal,
249
+ latest: item. value,
250
+ diffCompileTimes: true ) )
223
251
}
224
252
}
225
253
return comparisons
0 commit comments