Skip to content

Commit

Permalink
Merge branch 'main' into some-algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
ptoffy authored Mar 30, 2024
2 parents db162f7 + 28b9c44 commit 74ee4f6
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 16 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ jobs:
- name: Run benchmarks for PR branch
continue-on-error: true
run: |
cd Benchmarks
swift package -c release --allow-writing-to-directory .benchmarkBaselines/ benchmark baseline update pull_request --no-progress --quiet
swift package -c release --package-path Benchmarks --disable-sandbox benchmark baseline update pull_request
- name: Run benchmarks for 'main' branch
run: |
git stash
git checkout main
swift package -c release --allow-writing-to-directory .benchmarkBaselines/ benchmark baseline update main --no-progress --quiet
swift package -c release --package-path Benchmarks --disable-sandbox benchmark baseline update main
- name: Compare benchmarks
continue-on-error: true
run: |
date >> "${GITHUB_STEP_SUMMARY}"
swift package -c release benchmark baseline check main pull_request --format markdown >> "${GITHUB_STEP_SUMMARY}"
echo '---' >> "${GITHUB_STEP_SUMMARY}"
swift package -c release benchmark baseline compare main pull_request --no-progress --quiet --format markdown >> "${GITHUB_STEP_SUMMARY}"
swift package -c release --package-path Benchmarks benchmark baseline check main pull_request --format markdown >> "${GITHUB_STEP_SUMMARY}"
- name: Get formatted date
id: get-date
run: echo "date=$(date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_OUTPUT
Expand Down
26 changes: 23 additions & 3 deletions Benchmarks/Benchmarks/Signing/Signing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@ import Benchmark
import Foundation
import JWTKit

let customThresholds = BenchmarkThresholds(
relative: [.p25: 15.0, .p50: 15.0, .p75: 15.0, .p90: 15.0, .p99: 15.0],
absolute: [:]
)

let benchmarks = {
Benchmark("ES256") { benchmark in
Benchmark(
"ES256",
configuration: .init(
thresholds: [.peakMemoryResident: customThresholds]
)
) { benchmark in
let key = ES256PrivateKey()
let keyCollection = JWTKeyCollection()
await keyCollection.addES256(key: key)
Expand All @@ -12,7 +22,12 @@ let benchmarks = {
}
}

Benchmark("RSA") { benchmark in
Benchmark(
"RSA",
configuration: .init(
thresholds: [.peakMemoryResident: customThresholds]
)
) { benchmark in
let key = try Insecure.RSA.PrivateKey(pem: rsaPrivateKey)
let keyCollection = JWTKeyCollection()
await keyCollection.addRS256(key: key)
Expand All @@ -21,7 +36,12 @@ let benchmarks = {
}
}

Benchmark("EdDSA") { benchmark in
Benchmark(
"EdDSA",
configuration: .init(
thresholds: [.peakMemoryResident: customThresholds]
)
) { benchmark in
let key = try EdDSA.PrivateKey()
let keyCollection = JWTKeyCollection()
await keyCollection.addEdDSA(key: key)
Expand Down
40 changes: 35 additions & 5 deletions Benchmarks/Benchmarks/TokenLifecycle/TokenLifecycle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@ import Benchmark
import Foundation
import JWTKit

let customThresholds = BenchmarkThresholds(
relative: [.p25: 15.0, .p50: 15.0, .p75: 15.0, .p90: 15.0, .p99: 15.0],
absolute: [:]
)

let benchmarks = {
Benchmark("ES256 Generated") { benchmark in
Benchmark(
"ES256 Generated",
configuration: .init(
thresholds: [.peakMemoryResident: customThresholds]
)
) { benchmark in
for _ in benchmark.scaledIterations {
let key = ES256PrivateKey()
let keyCollection = JWTKeyCollection()
Expand All @@ -13,7 +23,12 @@ let benchmarks = {
}
}

Benchmark("ES256 PEM") { benchmark in
Benchmark(
"ES256 PEM",
configuration: .init(
thresholds: [.peakMemoryResident: customThresholds]
)
) { benchmark in
for _ in benchmark.scaledIterations {
let key = try ES256PrivateKey(pem: ecdsaPrivateKey)
let keyCollection = JWTKeyCollection()
Expand All @@ -23,7 +38,12 @@ let benchmarks = {
}
}

Benchmark("RSA PEM") { benchmark in
Benchmark(
"RSA PEM",
configuration: .init(
thresholds: [.peakMemoryResident: customThresholds]
)
) { benchmark in
for _ in benchmark.scaledIterations {
let key = try Insecure.RSA.PrivateKey(pem: rsaPrivateKey)
let keyCollection = JWTKeyCollection()
Expand All @@ -33,7 +53,12 @@ let benchmarks = {
}
}

Benchmark("EdDSA Generated") { benchmark in
Benchmark(
"EdDSA Generated",
configuration: .init(
thresholds: [.peakMemoryResident: customThresholds]
)
) { benchmark in
for _ in benchmark.scaledIterations {
let key = try EdDSA.PrivateKey()
let keyCollection = JWTKeyCollection()
Expand All @@ -43,7 +68,12 @@ let benchmarks = {
}
}

Benchmark("EdDSA Coordinates") { benchmark in
Benchmark(
"EdDSA Coordinates",
configuration: .init(
thresholds: [.peakMemoryResident: customThresholds]
)
) { benchmark in
for _ in benchmark.scaledIterations {
let key = try EdDSA.PrivateKey(x: eddsaPublicKeyBase64Url, d: eddsaPrivateKeyBase64Url, curve: .ed25519)
let keyCollection = JWTKeyCollection()
Expand Down
19 changes: 17 additions & 2 deletions Benchmarks/Benchmarks/Verifying/Verifying.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@ import Benchmark
import Foundation
import JWTKit

let customThresholds = BenchmarkThresholds(
relative: [.p25: 15.0, .p50: 15.0, .p75: 15.0, .p90: 15.0, .p99: 15.0],
absolute: [:]
)

let benchmarks = {
Benchmark("ES256") { benchmark in
Benchmark(
"ES256",
configuration: .init(
thresholds: [.peakMemoryResident: customThresholds]
)
) { benchmark in
let pem = """
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEEVs/o5+uQbTjL3chynL4wXgUg2R9
Expand All @@ -18,7 +28,12 @@ let benchmarks = {
}
}

Benchmark("RS256") { benchmark in
Benchmark(
"RS256",
configuration: .init(
thresholds: [.peakMemoryResident: customThresholds]
)
) { benchmark in
let pem = """
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu1SU1LfVLPHCozMxH2Mo
Expand Down

0 comments on commit 74ee4f6

Please sign in to comment.