mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Increase the precision of the performance benchmarks. (#20159)
This commit is contained in:
parent
a29c6d9bb2
commit
a96fb44911
@ -163,17 +163,15 @@ class TimelineSummary {
|
||||
double _averageInMillis(Iterable<Duration> durations) {
|
||||
if (durations.isEmpty)
|
||||
throw new ArgumentError('durations is empty!');
|
||||
|
||||
final int total = durations.fold<int>(0, (int t, Duration duration) => t + duration.inMilliseconds);
|
||||
final double total = durations.fold<double>(0.0, (double t, Duration duration) => t + duration.inMicroseconds.toDouble() / 1000.0);
|
||||
return total / durations.length;
|
||||
}
|
||||
|
||||
double _percentileInMillis(Iterable<Duration> durations, double percentile) {
|
||||
if (durations.isEmpty)
|
||||
throw new ArgumentError('durations is empty!');
|
||||
|
||||
assert(percentile >= 0.0 && percentile <= 100.0);
|
||||
final List<double> doubles = durations.map<double>((Duration duration) => duration.inMilliseconds.toDouble()).toList();
|
||||
final List<double> doubles = durations.map<double>((Duration duration) => duration.inMicroseconds.toDouble() / 1000.0).toList();
|
||||
doubles.sort();
|
||||
return doubles[((doubles.length - 1) * (percentile / 100)).round()];
|
||||
|
||||
@ -182,9 +180,8 @@ class TimelineSummary {
|
||||
double _maxInMillis(Iterable<Duration> durations) {
|
||||
if (durations.isEmpty)
|
||||
throw new ArgumentError('durations is empty!');
|
||||
|
||||
return durations
|
||||
.map<double>((Duration duration) => duration.inMilliseconds.toDouble())
|
||||
.map<double>((Duration duration) => duration.inMicroseconds.toDouble() / 1000.0)
|
||||
.reduce(math.max);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user