@@ -20,7 +20,7 @@ protocol ProgressReporter {
20
20
}
21
21
22
22
protocol BenchmarkReporter {
23
- mutating func report( results: [ BenchmarkResult ] , settings : BenchmarkSettings )
23
+ mutating func report( results: [ BenchmarkResult ] )
24
24
}
25
25
26
26
struct VerboseProgressReporter < Output: FlushableTextOutputStream > : ProgressReporter {
@@ -51,7 +51,7 @@ struct VerboseProgressReporter<Output: FlushableTextOutputStream>: ProgressRepor
51
51
struct QuietReporter : ProgressReporter , BenchmarkReporter {
52
52
mutating func report( running name: String , suite: String ) { }
53
53
mutating func report( finishedRunning name: String , suite: String , nanosTaken: UInt64 ) { }
54
- mutating func report( results: [ BenchmarkResult ] , settings : BenchmarkSettings ) { }
54
+ mutating func report( results: [ BenchmarkResult ] ) { }
55
55
}
56
56
57
57
struct ConsoleReporter < Output: FlushableTextOutputStream > : BenchmarkReporter {
@@ -61,9 +61,8 @@ struct ConsoleReporter<Output: FlushableTextOutputStream>: BenchmarkReporter {
61
61
self . output = output
62
62
}
63
63
64
- mutating func report( results: [ BenchmarkResult ] , settings: BenchmarkSettings ) {
65
- let ( rows, columns) = BenchmarkColumn . evaluate (
66
- results: results, settings: settings, pretty: true )
64
+ mutating func report( results: [ BenchmarkResult ] ) {
65
+ let ( rows, columns) = BenchmarkColumn . evaluate ( results: results, pretty: true )
67
66
68
67
let widths : [ BenchmarkColumn : Int ] = Dictionary (
69
68
uniqueKeysWithValues:
@@ -80,7 +79,12 @@ struct ConsoleReporter<Output: FlushableTextOutputStream>: BenchmarkReporter {
80
79
print ( " " , to: & output)
81
80
for (index, row) in rows. enumerated ( ) {
82
81
let components : [ String ] = columns. compactMap { column in
83
- let string = row [ column] !
82
+ var string : String
83
+ if let value = row [ column] {
84
+ string = value
85
+ } else {
86
+ string = " "
87
+ }
84
88
let width = widths [ column] !
85
89
let alignment = index == 0 ? . left : column. alignment
86
90
switch alignment {
@@ -108,12 +112,17 @@ struct CSVReporter<Output: FlushableTextOutputStream>: BenchmarkReporter {
108
112
self . output = output
109
113
}
110
114
111
- mutating func report( results: [ BenchmarkResult ] , settings: BenchmarkSettings ) {
112
- let ( rows, columns) = BenchmarkColumn . evaluate (
113
- results: results, settings: settings, pretty: false )
115
+ mutating func report( results: [ BenchmarkResult ] ) {
116
+ let ( rows, columns) = BenchmarkColumn . evaluate ( results: results, pretty: false )
114
117
115
118
for row in rows {
116
- let components : [ String ] = columns. compactMap { row [ $0] ! }
119
+ let components : [ String ] = columns. compactMap {
120
+ if let value = row [ $0] {
121
+ return value
122
+ } else {
123
+ return " "
124
+ }
125
+ }
117
126
let escaped = components. map { component -> String in
118
127
if component. contains ( " , " ) || component. contains ( " \" " ) || component. contains ( " \n " ) {
119
128
let escaped = component. replacingOccurrences ( of: " \" " , with: " \" \" " )
@@ -135,9 +144,8 @@ struct JSONReporter<Output: FlushableTextOutputStream>: BenchmarkReporter {
135
144
self . output = output
136
145
}
137
146
138
- mutating func report( results: [ BenchmarkResult ] , settings: BenchmarkSettings ) {
139
- let ( rows, columns) = BenchmarkColumn . evaluate (
140
- results: results, settings: settings, pretty: false )
147
+ mutating func report( results: [ BenchmarkResult ] ) {
148
+ let ( rows, columns) = BenchmarkColumn . evaluate ( results: results, pretty: false )
141
149
142
150
print ( " { " , to: & output)
143
151
print ( " \" benchmarks \" : [ " , to: & output)
@@ -151,13 +159,22 @@ struct JSONReporter<Output: FlushableTextOutputStream>: BenchmarkReporter {
151
159
// performance to ensure that output properly
152
160
// escapes special characters that could be
153
161
// present within the benchmark name.
154
- let name = row [ column] !
162
+ let name : String
163
+ if let value = row [ column] {
164
+ name = value
165
+ } else {
166
+ name = " "
167
+ }
155
168
let data = try ! JSONSerialization . data ( withJSONObject: [ name] )
156
169
var encoded = String ( data: data, encoding: . utf8) !
157
170
encoded = String ( encoded. dropFirst ( ) . dropLast ( ) )
158
171
rhs = encoded
159
172
} else {
160
- rhs = String ( row [ column] !)
173
+ if let value = row [ column] {
174
+ rhs = String ( value)
175
+ } else {
176
+ continue
177
+ }
161
178
}
162
179
let suffix = columnIndex != columns. count - 1 ? " , " : " "
163
180
print ( " \" \( column. name) \" : \( rhs) \( suffix) " , to: & output)
0 commit comments