Skip to content

Commit 9d73707

Browse files
authored
added inner product benchmarks (#241)
1 parent 2e08007 commit 9d73707

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

Benchmarks/RlweBenchmark/RlweBenchmark.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,37 @@ func ciphertextSwapRowsBenchmark<Scheme: HeScheme>(_: Scheme.Type) -> () -> Void
548548
}
549549
}
550550

551+
func ciphertextPlaintextInnerProductBenchmark<Scheme: HeScheme>(_: Scheme.Type, vectorCount: Int) -> () -> Void {
552+
{
553+
benchmark("CiphertextPlaintextInnerProduct", Scheme.self) { benchmark in
554+
let benchmarkContext: RlweBenchmarkContext<Scheme> = try StaticRlweBenchmarkContext.getBenchmarkContext()
555+
let ciphertexts = Array(repeating: benchmarkContext.evalCiphertext, count: vectorCount)
556+
let plaintexts = Array(repeating: benchmarkContext.evalPlaintext, count: vectorCount)
557+
benchmark.configuration.scalingFactor = .kilo
558+
benchmark.startMeasurement()
559+
for _ in benchmark.scaledIterations {
560+
try blackHole(Scheme.innerProduct(ciphertexts: ciphertexts, plaintexts: plaintexts))
561+
}
562+
}
563+
}
564+
}
565+
566+
func ciphertextCiphertextInnerProductBenchmark<Scheme: HeScheme>(_: Scheme.Type, vectorCount: Int) -> () -> Void {
567+
{
568+
benchmark("CiphertextCiphertextInnerProduct", Scheme.self) { benchmark in
569+
let benchmarkContext: RlweBenchmarkContext<Scheme> = try StaticRlweBenchmarkContext.getBenchmarkContext()
570+
let ciphertext = benchmarkContext.ciphertext
571+
let ciphertexts1 = Array(repeating: ciphertext, count: vectorCount)
572+
let ciphertexts2 = Array(repeating: ciphertext, count: vectorCount)
573+
benchmark.configuration.scalingFactor = .kilo
574+
benchmark.startMeasurement()
575+
for _ in benchmark.scaledIterations {
576+
try blackHole(Scheme.innerProduct(ciphertexts1, ciphertexts2))
577+
}
578+
}
579+
}
580+
}
581+
551582
// MARK: Serialization
552583

553584
func coeffPlaintextSerializeBenchmark<Scheme: HeScheme>(_: Scheme.Type) -> () -> Void {
@@ -770,6 +801,12 @@ nonisolated(unsafe) let benchmarks: () -> Void = {
770801
ciphertextSwapRowsBenchmark(Bfv<UInt32>.self)()
771802
ciphertextSwapRowsBenchmark(Bfv<UInt64>.self)()
772803

804+
ciphertextPlaintextInnerProductBenchmark(Bfv<UInt32>.self, vectorCount: 32)()
805+
ciphertextPlaintextInnerProductBenchmark(Bfv<UInt64>.self, vectorCount: 32)()
806+
807+
ciphertextCiphertextInnerProductBenchmark(Bfv<UInt32>.self, vectorCount: 8)()
808+
ciphertextCiphertextInnerProductBenchmark(Bfv<UInt64>.self, vectorCount: 8)()
809+
773810
// Serialization
774811
coeffPlaintextSerializeBenchmark(Bfv<UInt32>.self)()
775812
coeffPlaintextSerializeBenchmark(Bfv<UInt64>.self)()

0 commit comments

Comments
 (0)