Unverified Commit 457e98a1 authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

Add Sliders to `macrobenchmarks` (#125296)

This adds a performance test for `Slider` and `RangeSlider` to run on Android.
This is to measure upcoming changes to these widgets and compare their performance. 

https://user-images.githubusercontent.com/48603081/233633349-0bcad3c3-04a9-42dd-acd0-46b76ce51178.mp4
parent 9525934e
...@@ -34,6 +34,7 @@ const String kAnimatedComplexOpacityPerfRouteName = '/animated_complex_opacity'; ...@@ -34,6 +34,7 @@ const String kAnimatedComplexOpacityPerfRouteName = '/animated_complex_opacity';
const String kAnimatedComplexImageFilteredPerfRouteName = '/animated_complex_image_filtered'; const String kAnimatedComplexImageFilteredPerfRouteName = '/animated_complex_image_filtered';
const String kListTextLayoutRouteName = '/list_text_layout'; const String kListTextLayoutRouteName = '/list_text_layout';
const String kAnimatedBlurBackdropFilter = '/animated_blur_backdrop_filter'; const String kAnimatedBlurBackdropFilter = '/animated_blur_backdrop_filter';
const String kSlidersRouteName = '/sliders';
const String kOpacityPeepholeOneRectRouteName = '$kOpacityPeepholeRouteName/one_big_rect'; const String kOpacityPeepholeOneRectRouteName = '$kOpacityPeepholeRouteName/one_big_rect';
const String kOpacityPeepholeColumnOfOpacityRouteName = '$kOpacityPeepholeRouteName/column_of_opacity'; const String kOpacityPeepholeColumnOfOpacityRouteName = '$kOpacityPeepholeRouteName/column_of_opacity';
......
...@@ -34,6 +34,7 @@ import 'src/raster_cache_use_memory.dart'; ...@@ -34,6 +34,7 @@ import 'src/raster_cache_use_memory.dart';
import 'src/shader_mask_cache.dart'; import 'src/shader_mask_cache.dart';
import 'src/simple_animation.dart'; import 'src/simple_animation.dart';
import 'src/simple_scroll.dart'; import 'src/simple_scroll.dart';
import 'src/sliders.dart';
import 'src/stack_size.dart'; import 'src/stack_size.dart';
import 'src/text.dart'; import 'src/text.dart';
...@@ -85,6 +86,7 @@ class MacrobenchmarksApp extends StatelessWidget { ...@@ -85,6 +86,7 @@ class MacrobenchmarksApp extends StatelessWidget {
kListTextLayoutRouteName: (BuildContext context) => const ColumnOfText(), kListTextLayoutRouteName: (BuildContext context) => const ColumnOfText(),
kAnimatedComplexImageFilteredPerfRouteName: (BuildContext context) => const AnimatedComplexImageFiltered(), kAnimatedComplexImageFilteredPerfRouteName: (BuildContext context) => const AnimatedComplexImageFiltered(),
kAnimatedBlurBackdropFilter: (BuildContext context) => const AnimatedBlurBackdropFilter(), kAnimatedBlurBackdropFilter: (BuildContext context) => const AnimatedBlurBackdropFilter(),
kSlidersRouteName: (BuildContext context) => const SlidersPage(),
}, },
); );
} }
...@@ -319,6 +321,13 @@ class HomePage extends StatelessWidget { ...@@ -319,6 +321,13 @@ class HomePage extends StatelessWidget {
Navigator.pushNamed(context, kAnimatedBlurBackdropFilter); Navigator.pushNamed(context, kAnimatedBlurBackdropFilter);
}, },
), ),
ElevatedButton(
key: const Key(kSlidersRouteName),
child: const Text('Sliders'),
onPressed: () {
Navigator.pushNamed(context, kSlidersRouteName);
},
),
], ],
), ),
); );
......
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:ui';
import 'package:flutter/material.dart';
class SlidersPage extends StatefulWidget {
const SlidersPage({super.key});
@override
State<SlidersPage> createState() => _SlidersPageState();
}
class _SlidersPageState extends State<SlidersPage> with TickerProviderStateMixin {
late AnimationController _sliderController;
late Animation<double> _sliderAnimation;
double _sliderValue = 0.0;
RangeValues _rangeSliderValues = const RangeValues(0.0, 1.0);
@override
void initState() {
super.initState();
_sliderController = AnimationController(
duration: const Duration(seconds: 1),
vsync: this,
)..repeat();
_sliderAnimation = Tween<double>(begin: 0, end: 1).animate(_sliderController)
..addListener(() {
setState(() {
_sliderValue = _sliderAnimation.value;
_rangeSliderValues = RangeValues(
clampDouble(_sliderAnimation.value, 0, 0.45),
1.0 - clampDouble(_sliderAnimation.value, 0, 0.45),
);
});
});
}
@override
void dispose() {
_sliderController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Material(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Slider(
value: _sliderValue,
onChanged: (double value) { },
),
RangeSlider(
values: _rangeSliderValues,
onChanged: (RangeValues values) { },
),
],
),
);
}
}
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:macrobenchmarks/common.dart';
import 'util.dart';
void main() {
macroPerfTest(
'sliders_perf',
kSlidersRouteName,
pageDelay: const Duration(seconds: 1),
duration: const Duration(seconds: 10),
);
}
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:flutter_devicelab/framework/devices.dart';
import 'package:flutter_devicelab/framework/framework.dart';
import 'package:flutter_devicelab/tasks/perf_tests.dart';
Future<void> main() async {
deviceOperatingSystem = DeviceOperatingSystem.android;
await task(createSlidersPerfTest());
}
...@@ -308,6 +308,15 @@ TaskFunction createTextfieldPerfE2ETest() { ...@@ -308,6 +308,15 @@ TaskFunction createTextfieldPerfE2ETest() {
).run; ).run;
} }
TaskFunction createSlidersPerfTest() {
return PerfTest(
'${flutterDirectory.path}/dev/benchmarks/macrobenchmarks',
'test_driver/run_app.dart',
'sliders_perf',
testDriver: 'test_driver/sliders_perf_test.dart',
).run;
}
TaskFunction createStackSizeTest() { TaskFunction createStackSizeTest() {
final String testDirectory = final String testDirectory =
'${flutterDirectory.path}/dev/benchmarks/macrobenchmarks'; '${flutterDirectory.path}/dev/benchmarks/macrobenchmarks';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment