This reverts commit 2175e64e4f.
This commit is contained in:
@@ -2,7 +2,10 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
import 'dart:math' as math;
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import 'task_result.dart';
|
||||
|
||||
@@ -40,8 +43,8 @@ class ABTest {
|
||||
final String localEngine;
|
||||
final String taskName;
|
||||
final DateTime runStart;
|
||||
DateTime? _runEnd;
|
||||
DateTime? get runEnd => _runEnd;
|
||||
DateTime _runEnd;
|
||||
DateTime get runEnd => _runEnd;
|
||||
|
||||
final Map<String, List<double>> _aResults;
|
||||
final Map<String, List<double>> _bResults;
|
||||
@@ -88,15 +91,15 @@ class ABTest {
|
||||
kLocalEngineKeyName: localEngine,
|
||||
kTaskNameKeyName: taskName,
|
||||
kRunStartKeyName: runStart.toIso8601String(),
|
||||
kRunEndKeyName: runEnd!.toIso8601String(),
|
||||
kRunEndKeyName: runEnd.toIso8601String(),
|
||||
kAResultsKeyName: _aResults,
|
||||
kBResultsKeyName: _bResults,
|
||||
};
|
||||
|
||||
static void updateColumnLengths(List<int> lengths, List<String?> results) {
|
||||
static void updateColumnLengths(List<int> lengths, List<String> results) {
|
||||
for (int column = 0; column < lengths.length; column++) {
|
||||
if (results[column] != null) {
|
||||
lengths[column] = math.max(lengths[column], results[column]?.length ?? 0);
|
||||
lengths[column] = math.max(lengths[column], results[column].length);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,10 +107,10 @@ class ABTest {
|
||||
static void formatResult(StringBuffer buffer,
|
||||
List<int> lengths,
|
||||
List<FieldJustification> aligns,
|
||||
List<String?> values) {
|
||||
List<String> values) {
|
||||
for (int column = 0; column < lengths.length; column++) {
|
||||
final int len = lengths[column];
|
||||
String? value = values[column];
|
||||
String value = values[column];
|
||||
if (value == null) {
|
||||
value = ''.padRight(len);
|
||||
} else {
|
||||
@@ -139,9 +142,9 @@ class ABTest {
|
||||
final Map<String, _ScoreSummary> summariesA = _summarize(_aResults);
|
||||
final Map<String, _ScoreSummary> summariesB = _summarize(_bResults);
|
||||
|
||||
final List<List<String?>> tableRows = <List<String?>>[
|
||||
final List<List<String>> tableRows = <List<String>>[
|
||||
for (final String scoreKey in <String>{...summariesA.keys, ...summariesB.keys})
|
||||
<String?>[
|
||||
<String>[
|
||||
scoreKey,
|
||||
summariesA[scoreKey]?.averageString, summariesA[scoreKey]?.noiseString,
|
||||
summariesB[scoreKey]?.averageString, summariesB[scoreKey]?.noiseString,
|
||||
@@ -164,7 +167,7 @@ class ABTest {
|
||||
|
||||
final List<int> lengths = List<int>.filled(6, 0);
|
||||
updateColumnLengths(lengths, titles);
|
||||
for (final List<String?> row in tableRows) {
|
||||
for (final List<String> row in tableRows) {
|
||||
updateColumnLengths(lengths, row);
|
||||
}
|
||||
|
||||
@@ -174,7 +177,7 @@ class ABTest {
|
||||
FieldJustification.CENTER,
|
||||
...alignments.skip(1),
|
||||
], titles);
|
||||
for (final List<String?> row in tableRows) {
|
||||
for (final List<String> row in tableRows) {
|
||||
formatResult(buffer, lengths, alignments, row);
|
||||
}
|
||||
|
||||
@@ -189,7 +192,7 @@ class ABTest {
|
||||
buffer.writeln('$scoreKey:');
|
||||
buffer.write(' A:\t');
|
||||
if (_aResults.containsKey(scoreKey)) {
|
||||
for (final double score in _aResults[scoreKey]!) {
|
||||
for (final double score in _aResults[scoreKey]) {
|
||||
buffer.write('${score.toStringAsFixed(2)}\t');
|
||||
}
|
||||
} else {
|
||||
@@ -199,7 +202,7 @@ class ABTest {
|
||||
|
||||
buffer.write(' B:\t');
|
||||
if (_bResults.containsKey(scoreKey)) {
|
||||
for (final double score in _bResults[scoreKey]!) {
|
||||
for (final double score in _bResults[scoreKey]) {
|
||||
buffer.write('${score.toStringAsFixed(2)}\t');
|
||||
}
|
||||
} else {
|
||||
@@ -229,8 +232,8 @@ class ABTest {
|
||||
);
|
||||
|
||||
for (final String scoreKey in _allScoreKeys) {
|
||||
final _ScoreSummary? summaryA = summariesA[scoreKey];
|
||||
final _ScoreSummary? summaryB = summariesB[scoreKey];
|
||||
final _ScoreSummary summaryA = summariesA[scoreKey];
|
||||
final _ScoreSummary summaryB = summariesB[scoreKey];
|
||||
buffer.write('$scoreKey\t');
|
||||
|
||||
if (summaryA != null) {
|
||||
@@ -258,8 +261,8 @@ class ABTest {
|
||||
|
||||
class _ScoreSummary {
|
||||
_ScoreSummary({
|
||||
required this.average,
|
||||
required this.noise,
|
||||
@required this.average,
|
||||
@required this.noise,
|
||||
});
|
||||
|
||||
/// Average (arithmetic mean) of a series of values collected by a benchmark.
|
||||
@@ -272,14 +275,14 @@ class _ScoreSummary {
|
||||
String get averageString => average.toStringAsFixed(2);
|
||||
String get noiseString => '(${_ratioToPercent(noise)})';
|
||||
|
||||
String improvementOver(_ScoreSummary? other) {
|
||||
String improvementOver(_ScoreSummary other) {
|
||||
return other == null ? '' : '${(average / other.average).toStringAsFixed(2)}x';
|
||||
}
|
||||
}
|
||||
|
||||
void _addResult(TaskResult result, Map<String, List<double>> results) {
|
||||
for (final String scoreKey in result.benchmarkScoreKeys ?? <String>[]) {
|
||||
final double score = (result.data![scoreKey] as num).toDouble();
|
||||
for (final String scoreKey in result.benchmarkScoreKeys) {
|
||||
final double score = (result.data[scoreKey] as num).toDouble();
|
||||
results.putIfAbsent(scoreKey, () => <double>[]).add(score);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user