Skip to content

Commit 4d0c487

Browse files
authored
Fix divide-by-zero crash in animation_bench benchmark (#137539)
If the benchmark runs out of time before it closes the drawer it is animating, it tries to divide by zero when computing the time per frame. Don't report time per frame for activities with zero frames. This likely only happens for the close frame action, but guards are added to all time per frame computations in this benchmark.
1 parent 0d3cf28 commit 4d0c487

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

dev/benchmarks/microbenchmarks/lib/stocks/animation_bench.dart

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,29 @@ Future<void> main() async {
8383
unit: 's',
8484
name: 'stock_animation_total_run_time',
8585
);
86-
printer.addResult(
87-
description: ' Opening first frame average time',
88-
value: totalOpenFrameElapsedMicroseconds / totalOpenIterationCount,
89-
unit: 'µs per frame ($totalOpenIterationCount frames)',
90-
name: 'stock_animation_open_first_frame_average',
91-
);
92-
printer.addResult(
93-
description: ' Closing first frame average time',
94-
value: totalCloseFrameElapsedMicroseconds / totalCloseIterationCount,
95-
unit: 'µs per frame ($totalCloseIterationCount frames)',
96-
name: 'stock_animation_close_first_frame_average',
97-
);
98-
printer.addResult(
99-
description: ' Subsequent frames average time',
100-
value: totalSubsequentFramesElapsedMicroseconds / totalSubsequentFramesIterationCount,
101-
unit: 'µs per frame ($totalSubsequentFramesIterationCount frames)',
102-
name: 'stock_animation_subsequent_frame_average',
103-
);
86+
if (totalOpenIterationCount > 0) {
87+
printer.addResult(
88+
description: ' Opening first frame average time',
89+
value: totalOpenFrameElapsedMicroseconds / totalOpenIterationCount,
90+
unit: 'µs per frame ($totalOpenIterationCount frames)',
91+
name: 'stock_animation_open_first_frame_average',
92+
);
93+
}
94+
if (totalCloseIterationCount > 0) {
95+
printer.addResult(
96+
description: ' Closing first frame average time',
97+
value: totalCloseFrameElapsedMicroseconds / totalCloseIterationCount,
98+
unit: 'µs per frame ($totalCloseIterationCount frames)',
99+
name: 'stock_animation_close_first_frame_average',
100+
);
101+
}
102+
if (totalSubsequentFramesIterationCount > 0) {
103+
printer.addResult(
104+
description: ' Subsequent frames average time',
105+
value: totalSubsequentFramesElapsedMicroseconds / totalSubsequentFramesIterationCount,
106+
unit: 'µs per frame ($totalSubsequentFramesIterationCount frames)',
107+
name: 'stock_animation_subsequent_frame_average',
108+
);
109+
}
104110
printer.printToStdout();
105111
}

0 commit comments

Comments
 (0)