1
1
# Macrobenchmarks
2
2
3
- Performance benchmarks using flutter drive.
3
+ Performance benchmarks use either flutter drive or the web benchmark harness .
4
4
5
- ## Cull opacity benchmark
5
+ ## Mobile benchmarks
6
+
7
+ ### Cull opacity benchmark
6
8
7
9
To run the cull opacity benchmark on a device:
8
10
@@ -14,7 +16,7 @@ Results should be in the file `build/cull_opacity_perf.timeline_summary.json`.
14
16
15
17
More detailed logs should be in ` build/cull_opacity_perf.timeline.json ` .
16
18
17
- ## Cubic bezier benchmark
19
+ ### Cubic bezier benchmark
18
20
19
21
To run the cubic bezier benchmark on a device:
20
22
@@ -26,7 +28,7 @@ Results should be in the file `build/cubic_bezier_perf.timeline_summary.json`.
26
28
27
29
More detailed logs should be in ` build/cubic_bezier_perf.timeline.json ` .
28
30
29
- ## Backdrop filter benchmark
31
+ ### Backdrop filter benchmark
30
32
31
33
To run the backdrop filter benchmark on a device:
32
34
@@ -38,7 +40,7 @@ Results should be in the file `build/backdrop_filter_perf.timeline_summary.json`
38
40
39
41
More detailed logs should be in ` build/backdrop_filter_perf.timeline.json ` .
40
42
41
- ## Post Backdrop filter benchmark
43
+ ### Post Backdrop filter benchmark
42
44
43
45
To run the post-backdrop filter benchmark on a device:
44
46
@@ -49,3 +51,70 @@ flutter drive --profile test_driver/post_backdrop_filter_perf.dart
49
51
Results should be in the file ` build/post_backdrop_filter_perf.timeline_summary.json ` .
50
52
51
53
More detailed logs should be in ` build/post_backdrop_filter_perf.timeline.json ` .
54
+
55
+ ## Web benchmarks
56
+
57
+ Web benchmarks are compiled from the same entrypoint in ` lib/web_benchmarks.dart ` .
58
+
59
+ ### How to write a web benchmark
60
+
61
+ Create a new file for your benchmark under ` lib/src/web ` . See ` bench_draw_rect.dart `
62
+ as an example.
63
+
64
+ Choose one of the two benchmark types:
65
+
66
+ * A "raw benchmark" records performance metrics from direct interactions with
67
+ ` dart:ui ` with no framework. This kind of benchmark is good for benchmarking
68
+ low-level engine primitives, such as layer, picture, and semantics performance.
69
+ * A "widget benchmark" records performance metrics using a widget. This kind of
70
+ benchmark is good for measuring the performance of widgets, often together with
71
+ engine work that widget-under-test incurs.
72
+ * A "widget build benchmark" records the cost of building a widget from nothing.
73
+ This is different from the "widget benchmark" because typically the latter
74
+ only performs incremental UI updates, such as an animation. In contrast, this
75
+ benchmark pumps an empty frame to clear all previously built widgets and
76
+ rebuilds them from scratch.
77
+
78
+ For a raw benchmark extend ` RawRecorder ` (tip: you can start by copying
79
+ ` bench_draw_rect.dart ` ).
80
+
81
+ For a widget benchmark extend ` WidgetRecorder ` (tip: you can start by copying
82
+ ` bench_simple_lazy_text_scroll.dart ` ).
83
+
84
+ For a widget build benchmark extend ` WidgetBuildRecorder ` (tip: you can start by copying
85
+ ` bench_build_material_checkbox.dart ` ).
86
+
87
+ Pick a unique benchmark name and class name and add it to the ` benchmarks ` list
88
+ in ` lib/web_benchmarks.dart ` .
89
+
90
+ ### How to run a web benchmark
91
+
92
+ Web benchmarks can be run using ` flutter run ` in debug, profile, and release
93
+ modes, using either the HTML or the CanvasKit rendering backend. Note, however,
94
+ that running in debug mode will result in worse numbers. Profile mode is useful
95
+ for profiling in Chrome DevTools because the numbers are close to release mode
96
+ and the profile contains unobfuscated names.
97
+
98
+ Example:
99
+
100
+ ```
101
+ cd dev/benchmarks/macrobenchmarks
102
+
103
+ # Runs in profile mode using the HTML renderer
104
+ flutter run --profile -d web-server lib/web_benchmarks.dart
105
+
106
+ # Runs in profile mode using the CanvasKit renderer
107
+ flutter run --dart-define=FLUTTER_WEB_USE_SKIA=true --profile -d web-server lib/web_benchmarks.dart
108
+ ```
109
+
110
+ You can also run all benchmarks exactly like the devicelab runs them:
111
+
112
+ ```
113
+ cd dev/devicelab
114
+
115
+ # Runs using the HTML renderer
116
+ ../../bin/cache/dart-sdk/bin/dart bin/run.dart -t bin/tasks/web_benchmarks_html.dart
117
+
118
+ # Runs using the CanvasKit renderer
119
+ ../../bin/cache/dart-sdk/bin/dart bin/run.dart -t bin/tasks/web_benchmarks_canvaskit.dart
120
+ ```
0 commit comments