MNN/apps/iOS/MNNLLMChat/MNNLLMiOS/MainTab/Benchmark/Views/BenchmarkView.swift

72 lines
2.6 KiB
Swift
Raw Normal View History

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-08-29 15:38:24 +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-09-03 16:10:21 +08:00
.alert(String(localized: "Stop Benchmark"), isPresented: $viewModel.showStopConfirmation) {
Button(String(localized: "Yes"), role: .destructive) {
2025-07-11 10:58:37 +08:00
viewModel.onStopBenchmarkTapped()
}
2025-09-03 16:10:21 +08:00
Button(String(localized: "No"), role: .cancel) { }
2025-07-11 10:58:37 +08:00
} message: {
2025-09-03 16:10:21 +08:00
Text(String(localized: "Are you sure you want to stop the benchmark test?"))
2025-07-11 10:58:37 +08:00
}
2025-09-03 16:10:21 +08:00
.alert(String(localized: "Error"), isPresented: $viewModel.showError) {
Button(String(localized: "OK")) {
2025-08-11 11:28:08 +08:00
viewModel.dismissError()
}
2025-07-11 10:58:37 +08:00
} 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
}