Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a benchmark target and a script to run it #365

Merged
merged 4 commits into from
Jan 20, 2021
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
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