mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Restore the original name of the velocity tracker microbenchmark (#64060)
This commit is contained in:
parent
ce63f50733
commit
db705b81e3
@ -13,3 +13,10 @@ flutter run --release lib/stocks/layout_bench.dart
|
|||||||
```
|
```
|
||||||
|
|
||||||
The results should be in the device logs.
|
The results should be in the device logs.
|
||||||
|
|
||||||
|
### Avoid changing names of the benchmarks
|
||||||
|
|
||||||
|
Each microbenchmark is identified by a name, for example,
|
||||||
|
"catmullrom_transform_iteration". Changing the name of an existing
|
||||||
|
microbenchmarks will effectively remove the old benchmark and create a new one,
|
||||||
|
losing the historical data associated with the old benchmark in the process.
|
||||||
|
@ -9,15 +9,25 @@ import 'data/velocity_tracker_data.dart';
|
|||||||
|
|
||||||
const int _kNumIters = 10000;
|
const int _kNumIters = 10000;
|
||||||
|
|
||||||
|
class TrackerBenchmark {
|
||||||
|
TrackerBenchmark({ this.name, this.tracker });
|
||||||
|
|
||||||
|
final VelocityTracker tracker;
|
||||||
|
final String name;
|
||||||
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
assert(false, "Don't run benchmarks in checked mode! Use 'flutter run --release'.");
|
assert(false, "Don't run benchmarks in checked mode! Use 'flutter run --release'.");
|
||||||
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
|
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
|
||||||
final List<VelocityTracker> trackers = <VelocityTracker>[VelocityTracker(), IOSScrollViewFlingVelocityTracker()];
|
final List<TrackerBenchmark> benchmarks = <TrackerBenchmark>[
|
||||||
|
TrackerBenchmark(name: 'velocity_tracker_iteration', tracker: VelocityTracker()),
|
||||||
|
TrackerBenchmark(name: 'velocity_tracker_iteration_ios_fling', tracker: IOSScrollViewFlingVelocityTracker()),
|
||||||
|
];
|
||||||
final Stopwatch watch = Stopwatch();
|
final Stopwatch watch = Stopwatch();
|
||||||
|
|
||||||
for (final VelocityTracker tracker in trackers) {
|
for (final TrackerBenchmark benchmark in benchmarks) {
|
||||||
final String trackerType = tracker.runtimeType.toString();
|
print('${benchmark.name} benchmark...');
|
||||||
print('$trackerType benchmark...');
|
final VelocityTracker tracker = benchmark.tracker;
|
||||||
watch.reset();
|
watch.reset();
|
||||||
watch.start();
|
watch.start();
|
||||||
for (int i = 0; i < _kNumIters; i += 1) {
|
for (int i = 0; i < _kNumIters; i += 1) {
|
||||||
@ -30,10 +40,10 @@ void main() {
|
|||||||
}
|
}
|
||||||
watch.stop();
|
watch.stop();
|
||||||
printer.addResult(
|
printer.addResult(
|
||||||
description: 'Velocity tracker: $trackerType',
|
description: 'Velocity tracker: ${tracker.runtimeType}',
|
||||||
value: watch.elapsedMicroseconds / _kNumIters,
|
value: watch.elapsedMicroseconds / _kNumIters,
|
||||||
unit: 'µs per iteration',
|
unit: 'µs per iteration',
|
||||||
name: 'velocity_tracker_iteration_$trackerType',
|
name: benchmark.name,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user