Skip to content

Commit

Permalink
Add a benchmark target and a script to run it (#365)
Browse files Browse the repository at this point in the history
* Add a benchmark target and a script to run it

Benchmarks need to be built in the release mode, that's why I created a separate `benchmark.sh` script to build it and run it.

I've also cleaned up a compiler warning in `TextEditor.swift` and bumped macOS agents to use Xcode 12.3 instead of 12.2.

* Benchmark `App` and `WindowGroup` rendering

* Add a `benchmark` task to `tasks.json`

* Exit `NativeDemo` directory before benchmarking
  • Loading branch information
MaxDesiatov authored Jan 20, 2021
1 parent 67aea3c commit 6f0528f
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 3 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
shell: bash
run: |
set -ex
sudo xcode-select --switch /Applications/Xcode_12.2.app/Contents/Developer/
sudo xcode-select --switch /Applications/Xcode_12.3.app/Contents/Developer/
# avoid building unrelated products for testing by specifying the test product explicitly
swift build --product TokamakPackageTests
`xcrun --find xctest` .build/debug/TokamakPackageTests.xctest
Expand All @@ -42,6 +42,9 @@ jobs:
xcodebuild -scheme iOS -destination 'generic/platform=iOS' \
CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO | \
xcpretty --color
cd ..
./benchmark.sh
gtk_macos_build:
runs-on: macos-11.0
Expand All @@ -52,7 +55,7 @@ jobs:
shell: bash
run: |
set -ex
sudo xcode-select --switch /Applications/Xcode_12.2.app/Contents/Developer/
sudo xcode-select --switch /Applications/Xcode_12.3.app/Contents/Developer/
brew install gtk+3
Expand Down
5 changes: 5 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
"type": "shell",
"command": "carton dev --product TokamakDemo"
},
{
"label": "benchmark",
"type": "shell",
"command": "./benchmark.sh"
},
{
"label": "make",
"type": "shell",
Expand Down
18 changes: 18 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@
"revision": "a617ead8a125a97e69d6100e4d27922006e82e0a",
"version": "2.1.2"
}
},
{
"package": "swift-argument-parser",
"repositoryURL": "https://github.com/apple/swift-argument-parser",
"state": {
"branch": null,
"revision": "9564d61b08a5335ae0a36f789a7d71493eacadfc",
"version": "0.3.2"
}
},
{
"package": "Benchmark",
"repositoryURL": "https://github.com/google/swift-benchmark",
"state": {
"branch": null,
"revision": "8e0ef8bb7482ab97dcd2cd1d6855bd38921c345d",
"version": "0.1.0"
}
}
]
},
Expand Down
12 changes: 12 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ let package = Package(
name: "TokamakShim",
targets: ["TokamakShim"]
),
.executable(
name: "TokamakStaticHTMLBenchmark",
targets: ["TokamakStaticHTMLBenchmark"]
),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
Expand All @@ -52,6 +56,7 @@ let package = Package(
.package(url: "https://github.com/MaxDesiatov/Runtime.git", from: "2.1.2"),
.package(url: "https://github.com/TokamakUI/OpenCombine.git", from: "0.12.0-alpha3"),
.package(url: "https://github.com/swiftwasm/OpenCombineJS.git", .upToNextMinor(from: "0.0.2")),
.package(name: "Benchmark", url: "https://github.com/google/swift-benchmark", from: "0.1.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define
Expand Down Expand Up @@ -114,6 +119,13 @@ let package = Package(
"TokamakCore",
]
),
.target(
name: "TokamakStaticHTMLBenchmark",
dependencies: [
"Benchmark",
"TokamakStaticHTML",
]
),
.target(
name: "TokamakDOM",
dependencies: [
Expand Down
2 changes: 1 addition & 1 deletion Sources/TokamakCore/Views/Text/TextEditor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public struct TextEditor: View {
textBinding = text
}

public var body: some View {
public var body: Never {
neverBody("TextEditor")
}
}
Expand Down
24 changes: 24 additions & 0 deletions Sources/TokamakStaticHTMLBenchmark/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Benchmark
import TokamakStaticHTML

benchmark("render Text") {
_ = StaticHTMLRenderer(Text("text"))
}

struct BenchmarkApp: App {
var body: some Scene {
WindowGroup("Benchmark") {
Text("Hello, World!")
}
}
}

benchmark("render App") {
_ = StaticHTMLRenderer(BenchmarkApp())
}

benchmark("render List") {
_ = StaticHTMLRenderer(List(1..<100) { Text("\($0)") })
}

Benchmark.main()
6 changes: 6 additions & 0 deletions benchmark.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

set -eux

swift build -c release --product TokamakStaticHTMLBenchmark
./.build/release/TokamakStaticHTMLBenchmark

0 comments on commit 6f0528f

Please # to comment.