Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions Example/Example/BenchmarkApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//
// BenchmarkApp.swift
// Example
//
// Created by Kyle on 2025/6/23.
//
// Modified from https://gist.github.com/edudnyk/74ed8d3801004a6dcaab09868b522187

#if OPENSWIFTUI
import OpenSwiftUI
#else
import SwiftUI
#endif

#if os(iOS)
import UIKit
#endif

struct BenchmarkApp {
static func main() {
_TestApp().runBenchmarks([
Benchmark(),
])
}
}
#if os(iOS)
extension UIHostingController: _Test where Content == AnyView {}
extension UIHostingController: _ViewTest where Content == AnyView {
public func initRootView() -> AnyView {
return rootView
}
public func initSize() -> CGSize {
sizeThatFits(in: UIScreen.main.bounds.size)
}
}
#endif

struct PerformanceTest: _PerformanceTest {
var name = "RedColor Test"
func runTest(host: _BenchmarkHost, options: [AnyHashable : Any]) {
#if os(iOS)
let test = _makeUIHostingController(AnyView(RedColor())) as! UIHostingController<AnyView>
test.setUpTest()
test.render()
test._forEachIdentifiedView { proxy in
let state = test.stateForIdentifier(proxy.identifier, type: Bool.self, in: type(of: test.rootView))
let view = test.viewForIdentifier(proxy.identifier, AnyView.self)
print("IDENTIFIER: \(proxy)")
print("STATE: \(state)")
print("VIEW: \(view)")
}
test.tearDownTest()
#endif
}

}

struct RedColor: View {
var id: String { "RedColor" }

var body: some View {
Color.red._identified(by: id)
}
}

struct Benchmark: _Benchmark {
func setUpTest() {
print("DSF")
}

func measure(host: _BenchmarkHost) -> [Double] {
return [
host.measureAction {
PerformanceTest().runTest(host: host, options: [:])
},
]
}
}
11 changes: 11 additions & 0 deletions Example/Example/ExampleApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ import SwiftUI
#endif

@main
struct EntryPoint {
static func main() {
let runBenchmark = CommandLine.arguments.contains("benchmark")
if runBenchmark {
BenchmarkApp.main()
} else {
ExampleApp.main()
}
}
}

struct ExampleApp: App {
var body: some Scene {
WindowGroup {
Expand Down