Skip to content

Commit 5983f7f

Browse files
committed
WIP: Performance testing
1 parent 8b55263 commit 5983f7f

File tree

5 files changed

+185
-11
lines changed

5 files changed

+185
-11
lines changed

.github/workflows/pull_request.yml

Lines changed: 72 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,75 @@ concurrency:
99
cancel-in-progress: true
1010

1111
jobs:
12-
tests:
13-
name: Test
14-
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
15-
with:
16-
linux_exclude_swift_versions: "[{\"swift_version\": \"5.8\"}]"
17-
soundness:
18-
name: Soundness
19-
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
20-
with:
21-
license_header_check_project_name: "Swift.org"
22-
api_breakage_check_allowlist_path: "api-breakages.txt"
12+
# tests:
13+
# name: Test
14+
# uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
15+
# with:
16+
# linux_exclude_swift_versions: "[{\"swift_version\": \"5.8\"}]"
17+
# soundness:
18+
# name: Soundness
19+
# uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
20+
# with:
21+
# license_header_check_project_name: "Swift.org"
22+
# api_breakage_check_allowlist_path: "api-breakages.txt"
23+
performance_test:
24+
name: Performance test
25+
runs-on: ubuntu-latest
26+
container:
27+
image: swift:latest
28+
steps:
29+
# - name: Install libjemalloc-dev
30+
# run: apt-get update && apt-get install -y libjemalloc-dev
31+
# - name: Checkout repository
32+
# uses: actions/checkout@v4
33+
# with:
34+
# fetch-depth: 0
35+
# - name: Mark the workspace as safe
36+
# # https://github.com/actions/checkout/issues/766
37+
# run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
38+
# - name: Measure base branch performance
39+
# run: |
40+
# git checkout ${{ github.base_ref }}
41+
# swift package --package-path Benchmarks/ --allow-writing-to-directory Benchmarks/.benchmarkBaselines/ benchmark baseline update "${{ github.base_ref }}"
42+
# - name: Measure PR performance
43+
# run: |
44+
# git checkout ${{ github.head_ref }}
45+
# swift package --package-path Benchmarks/ --allow-writing-to-directory Benchmarks/.benchmarkBaselines/ benchmark baseline update "${{ github.head_ref }}"
46+
# - name: Compare performance measurements
47+
# id: compare_performance
48+
# run: |
49+
# if ! swift package --package-path Benchmarks benchmark baseline check "${{ github.base_ref }}" "${{ github.head_ref }}" > /tmp/comparison.md; then
50+
# echo "has_significant_changes=true" >> "$GITHUB_OUTPUT"
51+
# else
52+
# echo "has_significant_changes=false" >> "$GITHUB_OUTPUT"
53+
# fi
54+
- name: Install gh
55+
# if: ${{ steps.compare_performance.outputs.has_significant_changes == 'true' }}
56+
# Installation instructions from https://github.com/cli/cli/blob/trunk/docs/install_linux.md#debian-ubuntu-linux-raspberry-pi-os-apt
57+
run: |
58+
(type -p wget >/dev/null || (apt update && apt-get install wget -y)) \
59+
&& mkdir -p -m 755 /etc/apt/keyrings \
60+
&& out=$(mktemp) && wget -nv -O$out https://cli.github.com/packages/githubcli-archive-keyring.gpg \
61+
&& cat $out | tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \
62+
&& chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \
63+
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
64+
&& apt update \
65+
&& apt install gh -y
66+
- name: Post comment
67+
# if: ${{ steps.compare_performance.outputs.has_significant_changes == 'true' }}
68+
env:
69+
GH_TOKEN: ${{ github.token }}
70+
run: |
71+
COMMENT="Test"
72+
gh pr comment ${{ github.event.number }} --body "$COMMENT"
73+
74+
# # JSON_BODY=$(cat /tmp/comparison.md | jq -Rsa)
75+
# JSON_BODY=$(echo "Test" | jq -Rsa)
76+
# curl -L \
77+
# -X POST \
78+
# -H "Accept: application/vnd.github+json" \
79+
# -H "Authorization: Bearer ${{ github.token }}" \
80+
# -H "X-GitHub-Api-Version: 2022-11-28" \
81+
# https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.number }}/comments \
82+
# -d '{"body": $JSON_BODY}'
83+

Benchmarks/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
xcuserdata/
5+
DerivedData/
6+
.swiftpm/configuration/registries.json
7+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
8+
.netrc

Benchmarks/.vscode/launch.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"configurations": [
3+
{
4+
"type": "swift",
5+
"request": "launch",
6+
"args": [],
7+
"cwd": "${workspaceFolder:Benchmarks}",
8+
"name": "Debug Benchmarks",
9+
"program": "${workspaceFolder:Benchmarks}/.build/debug/Benchmarks",
10+
"preLaunchTask": "swift: Build Debug Benchmarks"
11+
},
12+
{
13+
"type": "swift",
14+
"request": "launch",
15+
"args": [],
16+
"cwd": "${workspaceFolder:Benchmarks}",
17+
"name": "Release Benchmarks",
18+
"program": "${workspaceFolder:Benchmarks}/.build/release/Benchmarks",
19+
"preLaunchTask": "swift: Build Release Benchmarks"
20+
},
21+
{
22+
"type": "swift",
23+
"request": "launch",
24+
"args": [],
25+
"cwd": "${workspaceFolder:Benchmarks}",
26+
"name": "Debug MyBenchmark",
27+
"program": "${workspaceFolder:Benchmarks}/.build/debug/MyBenchmark",
28+
"preLaunchTask": "swift: Build Debug MyBenchmark"
29+
},
30+
{
31+
"type": "swift",
32+
"request": "launch",
33+
"args": [],
34+
"cwd": "${workspaceFolder:Benchmarks}",
35+
"name": "Release MyBenchmark",
36+
"program": "${workspaceFolder:Benchmarks}/.build/release/MyBenchmark",
37+
"preLaunchTask": "swift: Build Release MyBenchmark"
38+
}
39+
]
40+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import Benchmark
2+
import Foundation
3+
4+
let benchmarks: @Sendable () -> Void = {
5+
let configuration = Benchmark.Configuration(
6+
metrics: [.instructions],
7+
thresholds: [.instructions: BenchmarkThresholds(relative: [.p25: 0.5, .p50: 0.5, .p75: 0.5, .p90: 0.5])]
8+
)
9+
Benchmark(
10+
"Fibonacci computation",
11+
configuration: configuration
12+
) { benchmark in
13+
blackHole(fibonacci(30))
14+
}
15+
}
16+
17+
func fibonacci(_ x: Int) -> Int {
18+
if x <= 0 {
19+
return 0
20+
}
21+
if x == 1 {
22+
return 1
23+
}
24+
return fibonacci(x - 2) + fibonacci(x - 1)
25+
}

Benchmarks/Package.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// swift-tools-version: 5.8
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// This source file is part of the SwiftCertificates open source project
5+
//
6+
// Copyright (c) 2023 Apple Inc. and the SwiftCertificates project authors
7+
// Licensed under Apache License v2.0
8+
//
9+
// See LICENSE.txt for license information
10+
// See CONTRIBUTORS.txt for the list of SwiftCertificates project authors
11+
//
12+
// SPDX-License-Identifier: Apache-2.0
13+
//
14+
//===----------------------------------------------------------------------===//
15+
16+
import PackageDescription
17+
18+
let package = Package(
19+
name: "benchmarks",
20+
platforms: [
21+
.macOS(.v13)
22+
],
23+
dependencies: [
24+
// .package(name: "swift-format", path: "../"),
25+
.package(url: "https://github.com/ordo-one/package-benchmark.git", from: "1.11.1"),
26+
],
27+
targets: [
28+
.executableTarget(
29+
name: "MyBenchmark",
30+
dependencies: [
31+
.product(name: "Benchmark", package: "package-benchmark"),
32+
// .product(name: "SwiftFormat", package: "swift-format"),
33+
],
34+
path: "Benchmarks/MyBenchmark",
35+
plugins: [
36+
.plugin(name: "BenchmarkPlugin", package: "package-benchmark")
37+
]
38+
)
39+
]
40+
)

0 commit comments

Comments
 (0)