@@ -6,7 +6,9 @@ extension BenchmarkRunner {
66 let url = URL ( fileURLWithPath: savePath, isDirectory: false )
77 let parent = url. deletingLastPathComponent ( )
88 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 )
1012 }
1113 print ( " Saving result to \( url. path) " )
1214 try results. save ( to: url)
@@ -21,7 +23,11 @@ extension BenchmarkRunner {
2123 }
2224
2325 /// 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 {
2531 let compareFileURL = URL ( fileURLWithPath: compareFilePath)
2632 let compareResult = try SuiteResult . load ( from: compareFileURL)
2733 let compareFile = compareFileURL. lastPathComponent
@@ -30,13 +36,22 @@ extension BenchmarkRunner {
3036 . compare ( with: compareResult)
3137 . filter ( { !$0. name. contains ( " _NS " ) } )
3238 . 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)
3443 if let saveFile = saveTo {
3544 try saveComparisons ( comparisons, path: saveFile)
3645 }
3746 }
3847
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 {
4055 let compareFileURL = URL ( fileURLWithPath: compareFilePath)
4156 let compareResult = try SuiteResult . load ( from: compareFileURL)
4257 let compareFile = compareFileURL. lastPathComponent
@@ -45,20 +60,30 @@ extension BenchmarkRunner {
4560 . compareCompileTimes ( with: compareResult)
4661 . filter ( { !$0. name. contains ( " _NS " ) } )
4762 . 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)
5068 }
5169
5270 /// Compares Swift Regex benchmark results against NSRegularExpression
5371 func compareWithNS( showChart: Bool , saveTo: String ? ) throws {
5472 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) " )
5677 if let saveFile = saveTo {
5778 try saveComparisons ( comparisons, path: saveFile)
5879 }
5980 }
6081
61- func displayComparisons( _ comparisons: [ BenchmarkResult . Comparison ] , _ showChart: Bool , against: String ) {
82+ func displayComparisons(
83+ _ comparisons: [ BenchmarkResult . Comparison ] ,
84+ _ showChart: Bool ,
85+ against: String
86+ ) {
6287 let regressions = comparisons. filter ( { $0. diff!. seconds > 0 } )
6388 . sorted ( by: { ( a, b) in a. diff!. seconds > b. diff!. seconds} )
6489 let improvements = comparisons. filter ( { $0. diff!. seconds < 0 } )
@@ -95,11 +120,16 @@ extension BenchmarkRunner {
95120 #endif
96121 }
97122
98- func saveComparisons( _ comparisons: [ BenchmarkResult . Comparison ] , path: String ) throws {
123+ func saveComparisons(
124+ _ comparisons: [ BenchmarkResult . Comparison ] ,
125+ path: String
126+ ) throws {
99127 let url = URL ( fileURLWithPath: path, isDirectory: false )
100128 let parent = url. deletingLastPathComponent ( )
101129 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 )
103133 }
104134
105135 var contents = " name,latest,baseline,diff,percentage \n "
@@ -112,17 +142,10 @@ extension BenchmarkRunner {
112142}
113143
114144struct BenchmarkResult : Codable {
145+ let compileTime : Time
115146 let median : Time
116- let estimatedCompileTime : Time
117147 let stdev : Double
118148 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- }
126149}
127150
128151extension BenchmarkResult {
@@ -135,7 +158,7 @@ extension BenchmarkResult {
135158
136159 var diff : Time ? {
137160 if diffCompileTimes {
138- return latest. estimatedCompileTime - baseline. estimatedCompileTime
161+ return latest. compileTime - baseline. compileTime
139162 }
140163 if Stats . tTest ( baseline, latest) {
141164 return latest. median - baseline. median
@@ -150,8 +173,8 @@ extension BenchmarkResult {
150173 let oldVal : Time
151174 let newVal : Time
152175 if diffCompileTimes {
153- oldVal = baseline. estimatedCompileTime
154- newVal = latest. estimatedCompileTime
176+ oldVal = baseline. compileTime
177+ newVal = latest. compileTime
155178 } else {
156179 oldVal = baseline. median
157180 newVal = latest. median
@@ -169,8 +192,8 @@ extension BenchmarkResult {
169192 let oldVal : Time
170193 let newVal : Time
171194 if diffCompileTimes {
172- oldVal = baseline. estimatedCompileTime
173- newVal = latest. estimatedCompileTime
195+ oldVal = baseline. compileTime
196+ newVal = latest. compileTime
174197 } else {
175198 oldVal = baseline. median
176199 newVal = latest. median
@@ -213,13 +236,18 @@ struct SuiteResult {
213236 return comparisons
214237 }
215238
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 ] {
218243 var comparisons : [ BenchmarkResult . Comparison ] = [ ]
219244 for item in results {
220245 if let otherVal = other. results [ item. key] {
221246 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 ) )
223251 }
224252 }
225253 return comparisons
0 commit comments