use the best of four results for flutter analyze --benchmark (#20058)

This commit is contained in:
Devon Carew 2018-08-01 11:24:41 -07:00 committed by GitHub
parent d2ab29d25e
commit 1393c73077
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,6 +4,7 @@
import 'dart:async';
import 'dart:io';
import 'dart:math' as math;
import 'package:path/path.dart' as path;
@ -11,7 +12,7 @@ import '../framework/framework.dart';
import '../framework/utils.dart';
/// Run each benchmark this many times and compute average.
const int _kRunsPerBenchmark = 3;
const int _kRunsPerBenchmark = 4;
/// Runs a benchmark once and reports the result as a lower-is-better numeric
/// value.
@ -90,13 +91,13 @@ class _MegaGalleryBenchmark {
/// Runs a [benchmark] several times and reports the average result.
Future<double> _run(_Benchmark benchmark) async {
double total = 0.0;
double best;
for (int i = 0; i < _kRunsPerBenchmark; i++) {
// Delete cached analysis results.
rmTree(dir('${Platform.environment['HOME']}/.dartServer'));
total += await benchmark();
final double result = await benchmark();
best = math.min(result, best ?? result);
}
final double average = total / _kRunsPerBenchmark;
return average;
return best;
}