@@ -19,7 +19,8 @@ import UIKit
1919struct BenchmarkApp {
2020 static func main( ) {
2121 _TestApp ( ) . runBenchmarks ( [
22- Benchmark ( ) ,
22+ RedBenchmark ( ) ,
23+ BlueBenchmark ( ) ,
2324 ] )
2425 }
2526}
@@ -36,10 +37,17 @@ extension UIHostingController: _ViewTest where Content == AnyView {
3637#endif
3738
3839struct PerformanceTest : _PerformanceTest {
39- var name = " RedColor Test "
40+ var name : String { " PerformanceTest " }
41+
42+ let view : AnyView
43+
44+ init ( _ view: some View ) {
45+ self . view = AnyView ( view)
46+ }
47+
4048 func runTest( host: _BenchmarkHost , options: [ AnyHashable : Any ] ) {
4149 #if os(iOS)
42- let test = _makeUIHostingController ( AnyView ( RedColor ( ) ) ) as! UIHostingController < AnyView >
50+ let test = _makeUIHostingController ( view ) as! UIHostingController < AnyView >
4351 test. setUpTest ( )
4452 test. render ( )
4553 test. _forEachIdentifiedView { proxy in
@@ -52,7 +60,6 @@ struct PerformanceTest: _PerformanceTest {
5260 test. tearDownTest ( )
5361 #endif
5462 }
55-
5663}
5764
5865struct RedColor : View {
@@ -63,15 +70,29 @@ struct RedColor: View {
6370 }
6471}
6572
66- struct Benchmark : _Benchmark {
67- func setUpTest( ) {
68- print ( " DSF " )
73+ struct BlueColor : View {
74+ var id : String { " BlueColor " }
75+
76+ var body : some View {
77+ Color . blue. _identified ( by: id)
78+ }
79+ }
80+
81+ struct RedBenchmark : _Benchmark {
82+ func measure( host: _BenchmarkHost ) -> [ Double ] {
83+ return [
84+ host. measureAction {
85+ PerformanceTest ( RedColor ( ) ) . runTest ( host: host, options: [ : ] )
86+ } ,
87+ ]
6988 }
89+ }
7090
91+ struct BlueBenchmark : _Benchmark {
7192 func measure( host: _BenchmarkHost ) -> [ Double ] {
7293 return [
7394 host. measureAction {
74- PerformanceTest ( ) . runTest ( host: host, options: [ : ] )
95+ PerformanceTest ( BlueColor ( ) ) . runTest ( host: host, options: [ : ] )
7596 } ,
7697 ]
7798 }
0 commit comments