|
| 1 | +// Copyright 2014 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import 'dart:io'; |
| 6 | + |
| 7 | +import 'package:flutter/material.dart'; |
| 8 | +import 'package:flutter/scheduler.dart'; |
| 9 | +import 'package:flutter_test/flutter_test.dart'; |
| 10 | + |
| 11 | +import 'benchmark_binding.dart'; |
| 12 | +import 'foundation/all_elements_bench.dart' as all_elements_bench; |
| 13 | +import 'foundation/change_notifier_bench.dart' as change_notifier_bench; |
| 14 | +import 'foundation/clamp.dart' as clamp; |
| 15 | +import 'foundation/decode_and_parse_asset_manifest.dart' |
| 16 | + as decode_and_parse_asset_manifest; |
| 17 | +import 'foundation/platform_asset_bundle.dart' as platform_asset_bundle; |
| 18 | +import 'foundation/standard_message_codec_bench.dart' |
| 19 | + as standard_message_codec_bench; |
| 20 | +import 'foundation/standard_method_codec_bench.dart' |
| 21 | + as standard_method_codec_bench; |
| 22 | +import 'foundation/timeline_bench.dart' as timeline_bench; |
| 23 | +import 'geometry/matrix_utils_transform_bench.dart' |
| 24 | + as matrix_utils_transform_bench; |
| 25 | +import 'geometry/rrect_contains_bench.dart' as rrect_contains_bench; |
| 26 | +import 'gestures/gesture_detector_bench.dart' as gesture_detector_bench; |
| 27 | +import 'gestures/velocity_tracker_bench.dart' as velocity_tracker_bench; |
| 28 | +import 'language/compute_bench.dart' as compute_bench; |
| 29 | +import 'language/sync_star_bench.dart' as sync_star_bench; |
| 30 | +import 'language/sync_star_semantics_bench.dart' as sync_star_semantics_bench; |
| 31 | +import 'layout/text_intrinsic_bench.dart' as text_intrinsic_bench; |
| 32 | +import 'stocks/animation_bench.dart' as animation_bench; |
| 33 | +import 'stocks/build_bench.dart' as build_bench; |
| 34 | +import 'stocks/build_bench_profiled.dart' as build_bench_profiled; |
| 35 | +import 'stocks/layout_bench.dart' as layout_bench; |
| 36 | +import 'ui/image_bench.dart' as image_bench; |
| 37 | + |
| 38 | +typedef Benchmark = (String name, Future<void> Function() value); |
| 39 | + |
| 40 | +Future<void> main() async { |
| 41 | + assert(false, |
| 42 | + "Don't run benchmarks in debug mode! Use 'flutter run --release'."); |
| 43 | + |
| 44 | + // BenchmarkingBinding is used by animation_bench, providing a simple |
| 45 | + // stopwatch interface over rendering. Lifting it here makes all |
| 46 | + // benchmarks run together. |
| 47 | + final BenchmarkingBinding binding = BenchmarkingBinding(); |
| 48 | + final List<Benchmark> benchmarks = <Benchmark>[ |
| 49 | + ('foundation/change_notifier_bench.dart', change_notifier_bench.execute), |
| 50 | + ('foundation/clamp.dart', clamp.execute), |
| 51 | + ('foundation/platform_asset_bundle.dart', platform_asset_bundle.execute), |
| 52 | + ( |
| 53 | + 'foundation/standard_message_codec_bench.dart', |
| 54 | + standard_message_codec_bench.execute |
| 55 | + ), |
| 56 | + ( |
| 57 | + 'foundation/standard_method_codec_bench.dart', |
| 58 | + standard_method_codec_bench.execute |
| 59 | + ), |
| 60 | + ('foundation/timeline_bench.dart', timeline_bench.execute), |
| 61 | + ( |
| 62 | + 'foundation/decode_and_parse_asset_manifest.dart', |
| 63 | + decode_and_parse_asset_manifest.execute |
| 64 | + ), |
| 65 | + ( |
| 66 | + 'geometry/matrix_utils_transform_bench.dart', |
| 67 | + matrix_utils_transform_bench.execute |
| 68 | + ), |
| 69 | + ('geometry/rrect_contains_bench.dart', rrect_contains_bench.execute), |
| 70 | + ('gestures/gesture_detector_bench.dart', gesture_detector_bench.execute), |
| 71 | + ('gestures/velocity_tracker_bench.dart', velocity_tracker_bench.execute), |
| 72 | + ('language/compute_bench.dart', compute_bench.execute), |
| 73 | + ('language/sync_star_bench.dart', sync_star_bench.execute), |
| 74 | + ( |
| 75 | + 'language/sync_star_semantics_bench.dart', |
| 76 | + sync_star_semantics_bench.execute |
| 77 | + ), |
| 78 | + ('stocks/animation_bench.dart', () => animation_bench.execute(binding)), |
| 79 | + ('stocks/build_bench.dart', build_bench.execute), |
| 80 | + ('stocks/build_bench_profiled.dart', build_bench_profiled.execute), |
| 81 | + ('stocks/layout_bench.dart', layout_bench.execute), |
| 82 | + ('ui/image_bench.dart', image_bench.execute), |
| 83 | + ('layout/text_intrinsic_bench.dart', text_intrinsic_bench.execute), |
| 84 | + ( |
| 85 | + 'foundation/all_elements_bench.dart', |
| 86 | + () async { |
| 87 | + binding.framePolicy = |
| 88 | + LiveTestWidgetsFlutterBindingFramePolicy.fullyLive; |
| 89 | + runApp(const SizedBox.shrink()); // ensure dispose |
| 90 | + await SchedulerBinding.instance.endOfFrame; |
| 91 | + all_elements_bench.execute(); |
| 92 | + } |
| 93 | + ), |
| 94 | + ]; |
| 95 | + |
| 96 | + print('╡ ••• Running microbenchmarks ••• ╞'); |
| 97 | + |
| 98 | + for (final Benchmark mark in benchmarks) { |
| 99 | + // Reset the frame policy to default - each test can set it on their own. |
| 100 | + binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fadePointers; |
| 101 | + print('╡ ••• Running ${mark.$1} ••• ╞'); |
| 102 | + await mark.$2(); |
| 103 | + } |
| 104 | + |
| 105 | + print('\n\n╡ ••• Done ••• ╞\n\n'); |
| 106 | + exit(0); |
| 107 | +} |
0 commit comments