OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 var tLimit = 1.96; | 166 var tLimit = 1.96; |
167 | 167 |
168 function tDist(n) | 168 function tDist(n) |
169 { | 169 { |
170 if (n > tMax) | 170 if (n > tMax) |
171 return tLimit; | 171 return tLimit; |
172 return tDistribution[n]; | 172 return tDistribution[n]; |
173 } | 173 } |
174 | 174 |
175 | 175 |
176 function formatResult(meanWidth, mean, stdErr, n) | 176 function formatResult(meanWidth, mean, stdErr, n, mode) |
177 { | 177 { |
| 178 // NaN mean means that the test did not run correctly. |
| 179 if (mean != mean) { |
| 180 var result = ""; |
| 181 for (var i = 0; i < meanWidth - 3; ++i) |
| 182 result += " "; |
| 183 if (mode == "test") |
| 184 result += "ERROR: Invalid test run."; |
| 185 else |
| 186 result += "ERROR: Some tests failed."; |
| 187 return result; |
| 188 } |
| 189 |
178 var meanString = mean.toFixed(1).toString(); | 190 var meanString = mean.toFixed(1).toString(); |
179 while (meanString.length < meanWidth) { | 191 while (meanString.length < meanWidth) { |
180 meanString = " " + meanString; | 192 meanString = " " + meanString; |
181 } | 193 } |
182 | 194 |
183 if (n == 1) | 195 if (n == 1) |
184 return meanString + "ms"; | 196 return meanString + "ms"; |
185 | 197 |
186 return meanString + "ms +/- " + ((tDist(n) * stdErr / mean) * 100).toFixed(1
) + "%"; | 198 return meanString + "ms +/- " + ((tDist(n) * stdErr / mean) * 100).toFixed(1
) + "%"; |
187 } | 199 } |
(...skipping 24 matching lines...) Expand all Loading... |
212 for (var test in testMeansByCategory[category]) { | 224 for (var test in testMeansByCategory[category]) { |
213 var candidate = testMeansByCategory[category][test].toFixed(2).toStr
ing().length; | 225 var candidate = testMeansByCategory[category][test].toFixed(2).toStr
ing().length; |
214 if (candidate > width) | 226 if (candidate > width) |
215 width = candidate; | 227 width = candidate; |
216 } | 228 } |
217 } | 229 } |
218 | 230 |
219 return width; | 231 return width; |
220 } | 232 } |
221 | 233 |
222 function resultLine(labelWidth, indent, label, meanWidth, mean, stdErr) | 234 function resultLine(labelWidth, indent, label, meanWidth, mean, stdErr, mode) |
223 { | 235 { |
224 var result = ""; | 236 var result = ""; |
225 for (i = 0; i < indent; i++) { | 237 for (i = 0; i < indent; i++) { |
226 result += " "; | 238 result += " "; |
227 } | 239 } |
228 | 240 |
229 result += label + ": "; | 241 result += label + ": "; |
230 | 242 |
231 for (i = 0; i < (labelWidth - (label.length + indent)); i++) { | 243 for (i = 0; i < (labelWidth - (label.length + indent)); i++) { |
232 result += " "; | 244 result += " "; |
233 } | 245 } |
234 | 246 |
235 return result + formatResult(meanWidth, mean, stdErr, count); | 247 return result + formatResult(meanWidth, mean, stdErr, count, mode); |
236 } | 248 } |
237 | 249 |
238 function printOutput() | 250 function printOutput() |
239 { | 251 { |
240 var labelWidth = computeLabelWidth(); | 252 var labelWidth = computeLabelWidth(); |
241 var meanWidth = computeMeanWidth(); | 253 var meanWidth = computeMeanWidth(); |
242 | 254 |
243 print("\n"); | 255 print("\n"); |
244 print("============================================"); | 256 print("============================================"); |
245 if (count == 1) | 257 if (count == 1) |
246 print("RESULTS"); | 258 print("RESULTS"); |
247 else | 259 else |
248 print("RESULTS (means and 95% confidence intervals)"); | 260 print("RESULTS (means and 95% confidence intervals)"); |
249 print("--------------------------------------------"); | 261 print("--------------------------------------------"); |
250 print(resultLine(labelWidth, 0, "Total", meanWidth, mean, stdErr)); | 262 print(resultLine(labelWidth, 0, "Total", meanWidth, mean, stdErr, "total")); |
251 print("--------------------------------------------"); | 263 print("--------------------------------------------"); |
252 for (var category in categoryMeans) { | 264 for (var category in categoryMeans) { |
253 print(""); | 265 print(""); |
254 print(resultLine(labelWidth, 2, category, meanWidth, categoryMeans[categ
ory], categoryStdErrs[category])); | 266 print(resultLine(labelWidth, 2, category, meanWidth, categoryMeans[categ
ory], categoryStdErrs[category], "category")); |
255 for (var test in testMeansByCategory[category]) { | 267 for (var test in testMeansByCategory[category]) { |
256 var shortName = test.replace(/^[^-]*-/, ""); | 268 var shortName = test.replace(/^[^-]*-/, ""); |
257 print(resultLine(labelWidth, 4, shortName, meanWidth, testMeansByCat
egory[category][test], testStdErrsByCategory[category][test])); | 269 print(resultLine(labelWidth, 4, shortName, meanWidth, testMeansByCat
egory[category][test], testStdErrsByCategory[category][test], "test")); |
258 } | 270 } |
259 } | 271 } |
260 } | 272 } |
261 | 273 |
262 initialize(); | 274 initialize(); |
263 computeItemTotals(); | 275 computeItemTotals(); |
264 computeTotals(); | 276 computeTotals(); |
265 computeMeans(); | 277 computeMeans(); |
266 computeStdDevs(); | 278 computeStdDevs(); |
267 computeStdErrors(); | 279 computeStdErrors(); |
268 printOutput(); | 280 printOutput(); |
OLD | NEW |