Skip to content
Open
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
2 changes: 2 additions & 0 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
- run: sudo xcode-select -s /Applications/Xcode_26.0.app
- run: swift --version
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- name: Install jemalloc
run: brew install jemalloc
- run: make all
- name: make fmt lint test (ComplianceSuite)
run: make fmt lint test
Expand Down
30 changes: 30 additions & 0 deletions Benchmarks/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// swift-tools-version: 6.0

import PackageDescription

let package = Package(
name: "swift-opa-benchmarks",
platforms: [
.macOS(.v13),
],
dependencies: [
.package(name: "swift-opa", path: ".."),
.package(url: "https://github.com/ordo-one/package-benchmark", from: "1.4.0"),
],
targets: [
.executableTarget(
name: "RegoBenchmarks",
dependencies: [
.product(name: "SwiftOPA", package: "swift-opa"),
.product(name: "Benchmark", package: "package-benchmark"),
],
path: "Sources",
swiftSettings: [
.enableExperimentalFeature("AccessLevelOnImport")
],
plugins: [
.plugin(name: "BenchmarkPlugin", package: "package-benchmark")
]
),
]
)
28 changes: 28 additions & 0 deletions Benchmarks/Sources/RegoBenchmarks.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import AST
import Benchmark
import Foundation
internal import Rego

let benchmarks: @Sendable () -> Void = {
Benchmark(
"Simple Policy Evaluation",
configuration: .init(metrics: [.wallClock, .mallocCountTotal])
) { benchmark in
// Setup OPA engine
var engine = OPA.Engine(
bundlePaths: [OPA.Engine.BundlePath(name: "simple", url: URL(fileURLWithPath: "../Tests/RegoTests/TestData/Bundles/simple-directory-bundle"))])
let preparedQuery = try! await engine.prepareForEvaluation(query: "data.app.rbac.allow")

let input: AST.RegoValue = [
"user": "alice",
"action": "read",
"resource": "document123",
]

benchmark.startMeasurement()
for _ in benchmark.scaledIterations {
let result = try! await preparedQuery.evaluate(input: input)
blackHole(result)
}
}
}
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ test:
test-compliance:
$(MAKE) -C ComplianceSuite test-compliance

.PHONY: perf
perf:
cd Benchmarks && swift package benchmark

.PHONY: build
build:
swift build
Expand Down