| 
									
										
										
										
											2025-06-20 17:39:06 +08:00
										 |  |  | // | 
					
						
							| 
									
										
										
										
											2025-07-11 10:58:37 +08:00
										 |  |  | //  BenchmarkView.swift | 
					
						
							|  |  |  | //  MNNLLMiOS | 
					
						
							| 
									
										
										
										
											2025-06-20 17:39:06 +08:00
										 |  |  | // | 
					
						
							| 
									
										
										
										
											2025-07-21 14:19:44 +08:00
										 |  |  | //  Created by 游薪渝(揽清) on 2025/7/21. | 
					
						
							| 
									
										
										
										
											2025-06-20 17:39:06 +08:00
										 |  |  | // | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import SwiftUI | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-11 10:58:37 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Main benchmark view that provides interface for running performance tests on ML models. | 
					
						
							|  |  |  |  * Features include model selection, progress tracking, and results visualization. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2025-06-20 17:39:06 +08:00
										 |  |  | struct BenchmarkView: View { | 
					
						
							| 
									
										
										
										
											2025-07-11 10:58:37 +08:00
										 |  |  |     @StateObject private var viewModel = BenchmarkViewModel() | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2025-06-20 17:39:06 +08:00
										 |  |  |     var body: some View { | 
					
						
							| 
									
										
										
										
											2025-07-21 14:19:44 +08:00
										 |  |  |         ZStack { | 
					
						
							|  |  |  |             ScrollView { | 
					
						
							|  |  |  |                 VStack(spacing: 24) { | 
					
						
							|  |  |  |                     // Model Selection Section | 
					
						
							|  |  |  |                     ModelSelectionCard( | 
					
						
							| 
									
										
										
										
											2025-08-05 15:43:12 +08:00
										 |  |  |                         viewModel: viewModel | 
					
						
							| 
									
										
										
										
											2025-07-21 14:19:44 +08:00
										 |  |  |                     ) | 
					
						
							|  |  |  |                      | 
					
						
							|  |  |  |                     // Progress Section | 
					
						
							|  |  |  |                     if viewModel.showProgressBar { | 
					
						
							|  |  |  |                         ProgressCard(progress: viewModel.currentProgress) | 
					
						
							|  |  |  |                             .transition(.asymmetric( | 
					
						
							|  |  |  |                                 insertion: .scale.combined(with: .opacity), | 
					
						
							|  |  |  |                                 removal: .opacity | 
					
						
							|  |  |  |                             )) | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                      | 
					
						
							|  |  |  |                     // Status Section | 
					
						
							|  |  |  |                     if !viewModel.statusMessage.isEmpty { | 
					
						
							|  |  |  |                         StatusCard(statusMessage: viewModel.statusMessage) | 
					
						
							|  |  |  |                             .transition(.slide) | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                      | 
					
						
							|  |  |  |                     // Results Section | 
					
						
							|  |  |  |                     if viewModel.showResults, let results = viewModel.benchmarkResults { | 
					
						
							|  |  |  |                         ResultsCard(results: results) | 
					
						
							|  |  |  |                             .transition(.asymmetric( | 
					
						
							|  |  |  |                                 insertion: .move(edge: .bottom).combined(with: .opacity), | 
					
						
							|  |  |  |                                 removal: .opacity | 
					
						
							|  |  |  |                             )) | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                      | 
					
						
							|  |  |  |                     Spacer(minLength: 20) | 
					
						
							| 
									
										
										
										
											2025-07-11 10:58:37 +08:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2025-07-21 14:19:44 +08:00
										 |  |  |                 .padding(.horizontal, 20) | 
					
						
							|  |  |  |                 .padding(.vertical, 16) | 
					
						
							| 
									
										
										
										
											2025-07-11 10:58:37 +08:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-08-05 15:43:12 +08:00
										 |  |  |         .alert("Stop Benchmark", isPresented: $viewModel.showStopConfirmation) { | 
					
						
							| 
									
										
										
										
											2025-07-11 10:58:37 +08:00
										 |  |  |             Button("Yes", role: .destructive) { | 
					
						
							|  |  |  |                 viewModel.onStopBenchmarkTapped() | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             Button("No", role: .cancel) { } | 
					
						
							|  |  |  |         } message: { | 
					
						
							|  |  |  |             Text("Are you sure you want to stop the benchmark test?") | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         .alert("Error", isPresented: $viewModel.showError) { | 
					
						
							|  |  |  |             Button("OK") { } | 
					
						
							|  |  |  |         } message: { | 
					
						
							|  |  |  |             Text(viewModel.errorMessage) | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-08-05 15:43:12 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-20 17:39:06 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-07-11 10:58:37 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 |