diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..5619341 Binary files /dev/null and b/.DS_Store differ diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml deleted file mode 100644 index 87e43ed..0000000 --- a/.github/workflows/build-and-test.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Build and Test - -on: - pull_request: - branches: [ "main" ] - workflow_dispatch: - -jobs: - build: - name: Build and Test using any available macOS - strategy: - fail-fast: false - matrix: - os: [macos-13] - runs-on: ${{ matrix.os }} - steps: - - name: Setup Xcode - uses: maxim-lobanov/setup-xcode@v1 - with: - xcode-version: '15.0' - - - name: Checkout - uses: actions/checkout@v3 - - - name: Build - env: - scheme: ${{ 'swiftui-simplex-architecture' }} - platform: ${{ 'macOS' }} - run: | - xcodebuild build-for-testing -scheme "$scheme" -destination "platform=$platform" - - - name: Test - env: - scheme: ${{ 'swiftui-simplex-architecture' }} - platform: ${{ 'macOS' }} - run: | - xcodebuild test-without-building -scheme "$scheme" -destination "platform=$platform" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..c3f1738 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,27 @@ +name: Test + +on: + pull_request: + branches: [ "main" ] + workflow_dispatch: + +jobs: + build: + name: Test + strategy: + fail-fast: false + matrix: + os: [macos-13] + runs-on: ${{ matrix.os }} + steps: + - name: Setup Xcode + uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: '15.0' + + - name: Checkout + uses: actions/checkout@v3 + + - name: Test + run: | + make test diff --git a/Makefile b/Makefile index 5b98780..979bc0e 100644 --- a/Makefile +++ b/Makefile @@ -11,3 +11,7 @@ format: .PHONY: test test: swift test -v + +.PHONY: benchmark +benchmark: + swift run --configuration release swiftui-simplex-architecture-benchmark diff --git a/Package.resolved b/Package.resolved index e567def..246cdcf 100644 --- a/Package.resolved +++ b/Package.resolved @@ -9,6 +9,24 @@ "version" : "1.0.0" } }, + { + "identity" : "swift-argument-parser", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-argument-parser", + "state" : { + "revision" : "8f4d2753f0e4778c76d5f05ad16c74f707390531", + "version" : "1.2.3" + } + }, + { + "identity" : "swift-benchmark", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/swift-benchmark", + "state" : { + "revision" : "8163295f6fe82356b0bcf8e1ab991645de17d096", + "version" : "0.1.2" + } + }, { "identity" : "swift-case-paths", "kind" : "remoteSourceControl", diff --git a/Package.swift b/Package.swift index 9ac7c1d..b51d5c2 100644 --- a/Package.swift +++ b/Package.swift @@ -26,6 +26,7 @@ let package = Package( .package(url: "https://github.com/pointfreeco/swift-dependencies.git", exact: "1.0.0"), .package(url: "https://github.com/pointfreeco/swiftui-navigation.git", exact: "1.0.2"), .package(url: "https://github.com/pointfreeco/swift-macro-testing.git", exact: "0.1.0"), + .package(url: "https://github.com/google/swift-benchmark", from: "0.1.0"), ], targets: [ // Targets are the basic building blocks of a package, defining a module or a test suite. @@ -40,6 +41,13 @@ let package = Package( .product(name: "SwiftUINavigation", package: "swiftui-navigation"), ] ), + .executableTarget( + name: "swiftui-simplex-architecture-benchmark", + dependencies: [ + "SimplexArchitecture", + .product(name: "Benchmark", package: "swift-benchmark"), + ] + ), .macro( name: "SimplexArchitectureMacrosPlugin", dependencies: [ diff --git a/Sources/swiftui-simplex-architecture-benchmark/ActionSendable.swift b/Sources/swiftui-simplex-architecture-benchmark/ActionSendable.swift new file mode 100644 index 0000000..292c1fc --- /dev/null +++ b/Sources/swiftui-simplex-architecture-benchmark/ActionSendable.swift @@ -0,0 +1,42 @@ +import SimplexArchitecture +import Benchmark +import Combine + +let actionSendableSuite = BenchmarkSuite(name: "ActionSendable") { + let testState = TestState() + + $0.benchmark("Mutate state") { + testState.count += 1 + } + + $0.benchmark("Send action") { + testState.send(.increment) + } +} + +private struct TestReducer: ReducerProtocol { + enum Action: Equatable { + case increment + } + + func reduce( + into state: StateContainer, + action: Action + ) -> SideEffect { + switch action { + case .increment: + state.count += 1 + return .none + } + } +} + +@ViewState +private final class TestState: ObservableObject { + @Published var count = 0 + let store: Store = .init(reducer: TestReducer()) + + init(count: Int = 0) { + self.count = count + } +} diff --git a/Sources/swiftui-simplex-architecture-benchmark/main.swift b/Sources/swiftui-simplex-architecture-benchmark/main.swift new file mode 100644 index 0000000..99e58aa --- /dev/null +++ b/Sources/swiftui-simplex-architecture-benchmark/main.swift @@ -0,0 +1,6 @@ +import Benchmark +import SimplexArchitecture + +Benchmark.main([ + actionSendableSuite +])