Skip to content

Commit 4008ac4

Browse files
authored
Make benchmarking opt-in (#188)
1 parent b786172 commit 4008ac4

File tree

5 files changed

+85
-70
lines changed

5 files changed

+85
-70
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ concurrency:
3030
env:
3131
SWIFTLINT_VERSION: 0.57.0
3232
SWIFTFORMAT_VERSION: 0.54.6
33+
SWIFT_HOMOMORPHIC_ENCRYPTION_ENABLE_BENCHMARKING: 1
3334
jobs:
3435
swift-tests:
3536
timeout-minutes: 15

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ Welcome to the Swift Homomorphic Encryption community! Thanks for your interest
55
### Pull Requests:
66
Before making a commit for a pull request, please run `pre-commit install`.
77
Then on each commit some basic formatting checks will be run.
8+
9+
Please also [enable benchmarking](README.md#Benchmarking).

Package.resolved

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 76 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// See the License for the specific language governing permissions and
1717
// limitations under the License.
1818

19+
import Foundation
1920
import PackageDescription
2021

2122
let librarySettings: [SwiftSetting] = []
@@ -227,71 +228,81 @@ let package = Package(
227228

228229
// MARK: - Benchmarks
229230

230-
package.dependencies += [
231-
.package(url: "https://github.com/ordo-one/package-benchmark", .upToNextMajor(from: "1.4.0")),
232-
]
233-
package.products += [.library(name: "_BenchmarkUtilities", targets: ["_BenchmarkUtilities"])]
234-
package.targets += [
235-
.target(
236-
name: "_BenchmarkUtilities",
237-
dependencies: [
238-
.product(name: "Benchmark", package: "package-benchmark"),
239-
"HomomorphicEncryption",
240-
"HomomorphicEncryptionProtobuf",
241-
"PrivateInformationRetrieval",
242-
"PrivateInformationRetrievalProtobuf",
243-
"PrivateNearestNeighborSearch",
244-
"PrivateNearestNeighborSearchProtobuf",
245-
],
246-
path: "Sources/BenchmarkUtilities",
247-
swiftSettings: benchmarkSettings),
248-
.executableTarget(
249-
name: "PolyBenchmark",
250-
dependencies: [
251-
.product(name: "Benchmark", package: "package-benchmark"),
252-
"HomomorphicEncryption",
253-
],
254-
path: "Benchmarks/PolyBenchmark",
255-
swiftSettings: benchmarkSettings,
256-
plugins: [
257-
.plugin(name: "BenchmarkPlugin", package: "package-benchmark"),
258-
]),
259-
.executableTarget(
260-
name: "RlweBenchmark",
261-
dependencies: [
262-
.product(name: "Benchmark", package: "package-benchmark"),
263-
"HomomorphicEncryption",
264-
],
265-
path: "Benchmarks/RlweBenchmark",
266-
swiftSettings: benchmarkSettings,
267-
plugins: [
268-
.plugin(name: "BenchmarkPlugin", package: "package-benchmark"),
269-
]),
270-
.executableTarget(
271-
name: "PIRBenchmark",
272-
dependencies: [
273-
.product(name: "Benchmark", package: "package-benchmark"),
274-
"HomomorphicEncryption",
275-
"_BenchmarkUtilities",
276-
],
277-
path: "Benchmarks/PrivateInformationRetrievalBenchmark",
278-
swiftSettings: benchmarkSettings,
279-
plugins: [
280-
.plugin(name: "BenchmarkPlugin", package: "package-benchmark"),
281-
]),
282-
.executableTarget(
283-
name: "PNNSBenchmark",
284-
dependencies: [
285-
.product(name: "Benchmark", package: "package-benchmark"),
286-
"HomomorphicEncryption",
287-
"_BenchmarkUtilities",
288-
],
289-
path: "Benchmarks/PrivateNearestNeighborSearchBenchmark",
290-
swiftSettings: benchmarkSettings,
291-
plugins: [
292-
.plugin(name: "BenchmarkPlugin", package: "package-benchmark"),
293-
]),
294-
]
231+
var enableBenchmarking: Bool {
232+
let benchmarkFlags = "SWIFT_HOMOMORPHIC_ENCRYPTION_ENABLE_BENCHMARKING"
233+
if let flag = ProcessInfo.processInfo.environment[benchmarkFlags], flag == "1" {
234+
return true
235+
}
236+
return false
237+
}
238+
239+
if enableBenchmarking {
240+
package.dependencies += [
241+
.package(url: "https://github.com/ordo-one/package-benchmark", .upToNextMajor(from: "1.4.0")),
242+
]
243+
package.products += [.library(name: "_BenchmarkUtilities", targets: ["_BenchmarkUtilities"])]
244+
package.targets += [
245+
.target(
246+
name: "_BenchmarkUtilities",
247+
dependencies: [
248+
.product(name: "Benchmark", package: "package-benchmark"),
249+
"HomomorphicEncryption",
250+
"HomomorphicEncryptionProtobuf",
251+
"PrivateInformationRetrieval",
252+
"PrivateInformationRetrievalProtobuf",
253+
"PrivateNearestNeighborSearch",
254+
"PrivateNearestNeighborSearchProtobuf",
255+
],
256+
path: "Sources/BenchmarkUtilities",
257+
swiftSettings: benchmarkSettings),
258+
.executableTarget(
259+
name: "PolyBenchmark",
260+
dependencies: [
261+
.product(name: "Benchmark", package: "package-benchmark"),
262+
"HomomorphicEncryption",
263+
],
264+
path: "Benchmarks/PolyBenchmark",
265+
swiftSettings: benchmarkSettings,
266+
plugins: [
267+
.plugin(name: "BenchmarkPlugin", package: "package-benchmark"),
268+
]),
269+
.executableTarget(
270+
name: "RlweBenchmark",
271+
dependencies: [
272+
.product(name: "Benchmark", package: "package-benchmark"),
273+
"HomomorphicEncryption",
274+
],
275+
path: "Benchmarks/RlweBenchmark",
276+
swiftSettings: benchmarkSettings,
277+
plugins: [
278+
.plugin(name: "BenchmarkPlugin", package: "package-benchmark"),
279+
]),
280+
.executableTarget(
281+
name: "PIRBenchmark",
282+
dependencies: [
283+
.product(name: "Benchmark", package: "package-benchmark"),
284+
"HomomorphicEncryption",
285+
"_BenchmarkUtilities",
286+
],
287+
path: "Benchmarks/PrivateInformationRetrievalBenchmark",
288+
swiftSettings: benchmarkSettings,
289+
plugins: [
290+
.plugin(name: "BenchmarkPlugin", package: "package-benchmark"),
291+
]),
292+
.executableTarget(
293+
name: "PNNSBenchmark",
294+
dependencies: [
295+
.product(name: "Benchmark", package: "package-benchmark"),
296+
"HomomorphicEncryption",
297+
"_BenchmarkUtilities",
298+
],
299+
path: "Benchmarks/PrivateNearestNeighborSearchBenchmark",
300+
swiftSettings: benchmarkSettings,
301+
plugins: [
302+
.plugin(name: "BenchmarkPlugin", package: "package-benchmark"),
303+
]),
304+
]
305+
}
295306

296307
// Set the minimum macOS version for the package
297308
#if canImport(Darwin)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ swift test --parallel
216216
217217
### Benchmarking
218218
Swift homomorphic encryption uses [Benchmark](https://github.com/ordo-one/package-benchmark) for benchmarking.
219+
To enable benchmarking, set the environment variable `SWIFT_HOMOMORPHIC_ENCRYPTION_ENABLE_BENCHMARKING=1`.
219220
By default, benchmarking requires the [jemalloc](http://jemalloc.net) dependency.
220221

221222
> [!WARNING]

0 commit comments

Comments
 (0)