Skip to content

Commit

Permalink
Add performance stress testing example for future expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
stackotter committed Oct 22, 2023
1 parent 1eca2bd commit b4293a5
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
67 changes: 67 additions & 0 deletions Examples/StressTest/StressTestApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import GtkBackend
import SwiftCrossUI

class StressTestState: Observable {
@Observed
var tab = 0

@Observed
var values: [Int: [String]] = [:]

let options: [String] = [
"red",
"green",
"blue",
"tower",
"power",
"flower",
"one",
"two",
"three",
"foo",
"bar",
"baz",
]
}

@main
struct StressTestApp: App {
typealias Backend = GtkBackend

let identifier = "dev.stackotter.StressTestApp"

let state = StressTestState()

let windowProperties = WindowProperties(
title: "StressTestApp",
defaultSize: WindowProperties.Size(400, 400),
resizable: true
)

var body: some View {
NavigationSplitView {
VStack {
Button("List 1") { state.tab = 0 }
Button("List 2") { state.tab = 1 }
}.padding(10)
} detail: {
VStack {
Button("Generate") {
var values: [String] = []
for _ in 0..<1000 {
values.append(state.options.randomElement()!)
}

state.values[state.tab] = values
}
if let values = state.values[state.tab] {
ScrollView {
ForEach(values) { value in
Text(value)
}
}
}
}.padding(10)
}
}
}
5 changes: 5 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ let package = Package(
dependencies: exampleDependencies,
path: "Examples/Spreadsheet"
),
.executableTarget(
name: "StressTestExample",
dependencies: exampleDependencies,
path: "Examples/StressTest"
),

.testTarget(
name: "SwiftCrossUITests",
Expand Down

0 comments on commit b4293a5

Please sign in to comment.