diff --git a/Benchmarks/RlweBenchmark/RlweBenchmark.swift b/Benchmarks/RlweBenchmark/RlweBenchmark.swift index 5db4bd79..c5fb2294 100644 --- a/Benchmarks/RlweBenchmark/RlweBenchmark.swift +++ b/Benchmarks/RlweBenchmark/RlweBenchmark.swift @@ -548,6 +548,37 @@ func ciphertextSwapRowsBenchmark(_: Scheme.Type) -> () -> Void } } +func ciphertextPlaintextInnerProductBenchmark(_: Scheme.Type, vectorCount: Int) -> () -> Void { + { + benchmark("CiphertextPlaintextInnerProduct", Scheme.self) { benchmark in + let benchmarkContext: RlweBenchmarkContext = try StaticRlweBenchmarkContext.getBenchmarkContext() + let ciphertexts = Array(repeating: benchmarkContext.evalCiphertext, count: vectorCount) + let plaintexts = Array(repeating: benchmarkContext.evalPlaintext, count: vectorCount) + benchmark.configuration.scalingFactor = .kilo + benchmark.startMeasurement() + for _ in benchmark.scaledIterations { + try blackHole(Scheme.innerProduct(ciphertexts: ciphertexts, plaintexts: plaintexts)) + } + } + } +} + +func ciphertextCiphertextInnerProductBenchmark(_: Scheme.Type, vectorCount: Int) -> () -> Void { + { + benchmark("CiphertextCiphertextInnerProduct", Scheme.self) { benchmark in + let benchmarkContext: RlweBenchmarkContext = try StaticRlweBenchmarkContext.getBenchmarkContext() + let ciphertext = benchmarkContext.ciphertext + let ciphertexts1 = Array(repeating: ciphertext, count: vectorCount) + let ciphertexts2 = Array(repeating: ciphertext, count: vectorCount) + benchmark.configuration.scalingFactor = .kilo + benchmark.startMeasurement() + for _ in benchmark.scaledIterations { + try blackHole(Scheme.innerProduct(ciphertexts1, ciphertexts2)) + } + } + } +} + // MARK: Serialization func coeffPlaintextSerializeBenchmark(_: Scheme.Type) -> () -> Void { @@ -770,6 +801,12 @@ nonisolated(unsafe) let benchmarks: () -> Void = { ciphertextSwapRowsBenchmark(Bfv.self)() ciphertextSwapRowsBenchmark(Bfv.self)() + ciphertextPlaintextInnerProductBenchmark(Bfv.self, vectorCount: 32)() + ciphertextPlaintextInnerProductBenchmark(Bfv.self, vectorCount: 32)() + + ciphertextCiphertextInnerProductBenchmark(Bfv.self, vectorCount: 8)() + ciphertextCiphertextInnerProductBenchmark(Bfv.self, vectorCount: 8)() + // Serialization coeffPlaintextSerializeBenchmark(Bfv.self)() coeffPlaintextSerializeBenchmark(Bfv.self)()