forked from firka/flutter
resurrect analyzer benchmarks (#10668)
* resurrect analyzer benchmarks * move analyzer_benchmark to the more stable linux/android * report average rather than best result
This commit is contained in:
@@ -1,62 +0,0 @@
|
||||
// Copyright (c) 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'framework.dart';
|
||||
|
||||
/// A benchmark harness used to run a benchmark multiple times and report the
|
||||
/// best result.
|
||||
abstract class Benchmark {
|
||||
Benchmark(this.name);
|
||||
|
||||
final String name;
|
||||
|
||||
TaskResult bestResult;
|
||||
|
||||
Future<Null> init() => new Future<Null>.value();
|
||||
|
||||
Future<num> run();
|
||||
TaskResult get lastResult;
|
||||
|
||||
@override
|
||||
String toString() => name;
|
||||
}
|
||||
|
||||
/// Runs a [benchmark] [iterations] times and reports the best result.
|
||||
///
|
||||
/// Use [warmUpBenchmark] to discard cold performance results.
|
||||
Future<num> runBenchmark(Benchmark benchmark, {
|
||||
int iterations: 1,
|
||||
bool warmUpBenchmark: false
|
||||
}) async {
|
||||
await benchmark.init();
|
||||
|
||||
final List<num> allRuns = <num>[];
|
||||
|
||||
num minValue;
|
||||
|
||||
if (warmUpBenchmark)
|
||||
await benchmark.run();
|
||||
|
||||
while (iterations > 0) {
|
||||
iterations--;
|
||||
|
||||
print('');
|
||||
|
||||
try {
|
||||
final num result = await benchmark.run();
|
||||
allRuns.add(result);
|
||||
|
||||
if (minValue == null || result < minValue) {
|
||||
benchmark.bestResult = benchmark.lastResult;
|
||||
minValue = result;
|
||||
}
|
||||
} catch (error) {
|
||||
print('benchmark failed with error: $error');
|
||||
}
|
||||
}
|
||||
|
||||
return minValue;
|
||||
}
|
||||
@@ -380,35 +380,6 @@ void checkNotNull(Object o1,
|
||||
throw 'o10 is null';
|
||||
}
|
||||
|
||||
/// Add benchmark values to a JSON results file.
|
||||
///
|
||||
/// If the file contains information about how long the benchmark took to run
|
||||
/// (a `time` field), then return that info.
|
||||
// TODO(yjbanov): move this data to __metadata__
|
||||
num addBuildInfo(File jsonFile,
|
||||
{num expected, String sdk, String commit, DateTime timestamp}) {
|
||||
Map<String, dynamic> json;
|
||||
|
||||
if (jsonFile.existsSync())
|
||||
json = JSON.decode(jsonFile.readAsStringSync());
|
||||
else
|
||||
json = <String, dynamic>{};
|
||||
|
||||
if (expected != null)
|
||||
json['expected'] = expected;
|
||||
if (sdk != null)
|
||||
json['sdk'] = sdk;
|
||||
if (commit != null)
|
||||
json['commit'] = commit;
|
||||
if (timestamp != null)
|
||||
json['timestamp'] = timestamp.millisecondsSinceEpoch;
|
||||
|
||||
jsonFile.writeAsStringSync(jsonEncode(json));
|
||||
|
||||
// Return the elapsed time of the benchmark (if any).
|
||||
return json['time'];
|
||||
}
|
||||
|
||||
/// Splits [from] into lines and selects those that contain [pattern].
|
||||
Iterable<String> grep(Pattern pattern, {@required String from}) {
|
||||
return from.split('\n').where((String line) {
|
||||
|
||||
Reference in New Issue
Block a user