Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * The results of a single block of tests (count times run, overall time). | 6 * The results of a single block of tests (count times run, overall time). |
| 7 */ | 7 */ |
| 8 class BlockSample { | 8 class BlockSample { |
| 9 BlockSample(this.count, this.durationNanos); | 9 BlockSample(this.count, this.durationNanos); |
| 10 int count; | 10 int count; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 double n = source.length.toDouble(); | 51 double n = source.length.toDouble(); |
| 52 double sumY = BlockSample._totalTime(source).toDouble(); | 52 double sumY = BlockSample._totalTime(source).toDouble(); |
| 53 double sumXSquared = BlockSample._sum(source, | 53 double sumXSquared = BlockSample._sum(source, |
| 54 int _(BlockSample s) => s.count * s.count).toDouble(); | 54 int _(BlockSample s) => s.count * s.count).toDouble(); |
| 55 double sumX = BlockSample._totalCount(source).toDouble(); | 55 double sumX = BlockSample._totalCount(source).toDouble(); |
| 56 double sumXY = BlockSample._sum(source, | 56 double sumXY = BlockSample._sum(source, |
| 57 int _(BlockSample s) => s.durationNanos * s.count).toDouble(); | 57 int _(BlockSample s) => s.durationNanos * s.count).toDouble(); |
| 58 | 58 |
| 59 overheadNanos = | 59 overheadNanos = |
| 60 ((((sumY * sumXSquared) - (sumX * sumXY)) / | 60 ((((sumY * sumXSquared) - (sumX * sumXY)) / |
| 61 ((n * sumXSquared) - (sumX * sumX))) / source.length).toInt(); | 61 ((n * sumXSquared) - (sumX * sumX))) / source.length).truncate(); |
|
Lasse Reichstein Nielsen
2013/01/04 10:29:42
Indent by one more here.
| |
| 62 | 62 |
| 63 perRequestNanos = | 63 perRequestNanos = |
| 64 (((n * sumXY) - (sumX * sumY)) / | 64 (((n * sumXY) - (sumX * sumY)) / |
| 65 ((n * sumXSquared) - (sumX * sumX))).toInt(); | 65 ((n * sumXSquared) - (sumX * sumX))).truncate(); |
|
Lasse Reichstein Nielsen
2013/01/04 10:29:42
Ditto.
| |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 | 68 |
| 69 bool isValid() => overheadNanos >= 0 && perRequestNanos >= 0; | 69 bool isValid() => overheadNanos >= 0 && perRequestNanos >= 0; |
| 70 | 70 |
| 71 int overheadNanos; | 71 int overheadNanos; |
| 72 int perRequestNanos; | 72 int perRequestNanos; |
| 73 int repsFor(int targetDurationNanos, [int blocksize = -1]) { | 73 int repsFor(int targetDurationNanos, [int blocksize = -1]) { |
| 74 if (blocksize <= 0) { | 74 if (blocksize <= 0) { |
| 75 return ((targetDurationNanos - overheadNanos) / perRequestNanos).toInt(); | 75 return ((targetDurationNanos - overheadNanos) / perRequestNanos).truncate( ); |
|
Lasse Reichstein Nielsen
2013/01/04 10:29:42
Long line. Use ~/ ?
| |
| 76 } else { | 76 } else { |
| 77 int blockTime = overheadNanos + (blocksize * perRequestNanos); | 77 int blockTime = overheadNanos + (blocksize * perRequestNanos); |
| 78 int fullBlocks = targetDurationNanos ~/ blockTime; | 78 int fullBlocks = targetDurationNanos ~/ blockTime; |
| 79 int extraReps = | 79 int extraReps = |
| 80 ((targetDurationNanos - (fullBlocks * blockTime)) - overheadNanos) | 80 ((targetDurationNanos - (fullBlocks * blockTime)) - overheadNanos) |
| 81 ~/ perRequestNanos; | 81 ~/ perRequestNanos; |
| 82 return ((fullBlocks * blocksize) + extraReps).toInt(); | 82 return ((fullBlocks * blocksize) + extraReps).truncate(); |
|
Lasse Reichstein Nielsen
2013/01/04 10:29:42
All operands are int, so drop truncate.
| |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 | 86 |
| 87 /** | 87 /** |
| 88 * Report overall test performance | 88 * Report overall test performance |
| 89 */ | 89 */ |
| 90 class TestReport { | 90 class TestReport { |
| 91 TestReport(this.id, this.desc, this.warmup, this.results) { | 91 TestReport(this.id, this.desc, this.warmup, this.results) { |
| 92 spaceChar = " ".charCodes[0]; | 92 spaceChar = " ".charCodes[0]; |
| 93 } | 93 } |
| 94 | 94 |
| 95 int spaceChar; | 95 int spaceChar; |
| 96 | 96 |
| 97 int resultsCount() => BlockSample._totalCount(results); | 97 int resultsCount() => BlockSample._totalCount(results); |
| 98 | 98 |
| 99 int resultsNanos() => BlockSample._totalTime(results); | 99 int resultsNanos() => BlockSample._totalTime(results); |
| 100 | 100 |
| 101 int resultsBestNanos() { | 101 int resultsBestNanos() { |
| 102 BlockSample best = bestBlock(results); | 102 BlockSample best = bestBlock(results); |
| 103 return best.durationNanos ~/ best.count; | 103 return best.durationNanos ~/ best.count; |
| 104 } | 104 } |
| 105 | 105 |
| 106 int resultsMeanNanos() => | 106 int resultsMeanNanos() => |
| 107 (BlockSample._totalTime(results) / | 107 (BlockSample._totalTime(results) ~/ |
| 108 BlockSample._totalCount(results)).toInt(); | 108 BlockSample._totalCount(results)); |
|
Lasse Reichstein Nielsen
2013/01/04 10:29:42
Indent by 1 more, or put on same line if possible.
floitsch
2013/03/11 13:39:15
Done in a different CL.
| |
| 109 | 109 |
| 110 int resultsWorstNanos() { | 110 int resultsWorstNanos() { |
| 111 BlockSample worst = worstBlock(results); | 111 BlockSample worst = worstBlock(results); |
| 112 return worst.durationNanos / worst.count; | 112 return worst.durationNanos / worst.count; |
| 113 } | 113 } |
| 114 | 114 |
| 115 int warmupBestNanos() { | 115 int warmupBestNanos() { |
| 116 BlockSample best = bestBlock(warmup); | 116 BlockSample best = bestBlock(warmup); |
| 117 return best.durationNanos / best.count; | 117 return best.durationNanos / best.count; |
| 118 } | 118 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 outCodes.insertRange(0, width, spaceChar); | 178 outCodes.insertRange(0, width, spaceChar); |
| 179 outCodes.setRange(Math.max(0, width - s.length), Math.min(width, s.length), | 179 outCodes.setRange(Math.max(0, width - s.length), Math.min(width, s.length), |
| 180 s.charCodes); | 180 s.charCodes); |
| 181 return new String.fromCharCodes(outCodes); | 181 return new String.fromCharCodes(outCodes); |
| 182 } | 182 } |
| 183 | 183 |
| 184 static String _stringifyDoubleAsInt(double val) { | 184 static String _stringifyDoubleAsInt(double val) { |
| 185 if (val.isInfinite || val.isNaN) { | 185 if (val.isInfinite || val.isNaN) { |
| 186 return "NaN"; | 186 return "NaN"; |
| 187 } else { | 187 } else { |
| 188 return val.toInt().toString(); | 188 return val.truncate().toString(); |
|
Lasse Reichstein Nielsen
2013/01/04 10:29:42
.toStringAsFixed(0)
| |
| 189 } | 189 } |
| 190 } | 190 } |
| 191 | 191 |
| 192 String id; | 192 String id; |
| 193 String desc; | 193 String desc; |
| 194 List<BlockSample> warmup; | 194 List<BlockSample> warmup; |
| 195 List<BlockSample> results; | 195 List<BlockSample> results; |
| 196 } | 196 } |
| 197 | 197 |
| 198 class Runner { | 198 class Runner { |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 450 _(TestReport r) => r.printReport() : reportHandler; | 450 _(TestReport r) => r.printReport() : reportHandler; |
| 451 } | 451 } |
| 452 | 452 |
| 453 Function _reportHandler; | 453 Function _reportHandler; |
| 454 Function get reportHandler => _reportHandler; | 454 Function get reportHandler => _reportHandler; |
| 455 int _warmup; | 455 int _warmup; |
| 456 int _targetTimeMs; | 456 int _targetTimeMs; |
| 457 int _minSampleTimeMs; | 457 int _minSampleTimeMs; |
| 458 int _blocksize; | 458 int _blocksize; |
| 459 } | 459 } |
| OLD | NEW |