(iter_count=10)
| 5 | |
| 6 | |
| 7 | def bench_bfv(iter_count=10): |
| 8 | print_example_banner("Example: Performance / BFV") |
| 9 | |
| 10 | parms = EncryptionParameters(scheme_type.bfv) |
| 11 | poly_modulus_degree = 8192 |
| 12 | parms.set_poly_modulus_degree(poly_modulus_degree) |
| 13 | parms.set_coeff_modulus(CoeffModulus.BFVDefault(poly_modulus_degree)) |
| 14 | parms.set_plain_modulus(PlainModulus.Batching(poly_modulus_degree, 20)) |
| 15 | |
| 16 | context = SEALContext(parms) |
| 17 | keygen = KeyGenerator(context) |
| 18 | encryptor = Encryptor(context, keygen.create_public_key()) |
| 19 | evaluator = Evaluator(context) |
| 20 | decryptor = Decryptor(context, keygen.secret_key()) |
| 21 | batch_encoder = BatchEncoder(context) |
| 22 | relin_keys = keygen.create_relin_keys() |
| 23 | |
| 24 | slot_count = batch_encoder.slot_count() |
| 25 | data = np.arange(slot_count, dtype=np.uint64) |
| 26 | |
| 27 | t0 = time.perf_counter() |
| 28 | for _ in range(iter_count): |
| 29 | plain = batch_encoder.encode(data) |
| 30 | t1 = time.perf_counter() |
| 31 | |
| 32 | plain = batch_encoder.encode(data) |
| 33 | t2 = time.perf_counter() |
| 34 | for _ in range(iter_count): |
| 35 | encrypted = encryptor.encrypt(plain) |
| 36 | t3 = time.perf_counter() |
| 37 | |
| 38 | encrypted = encryptor.encrypt(plain) |
| 39 | t4 = time.perf_counter() |
| 40 | for _ in range(iter_count): |
| 41 | decryptor.decrypt(encrypted) |
| 42 | t5 = time.perf_counter() |
| 43 | |
| 44 | ct = encryptor.encrypt(plain) |
| 45 | t6 = time.perf_counter() |
| 46 | for _ in range(iter_count): |
| 47 | tct = evaluator.square(ct) |
| 48 | evaluator.relinearize_inplace(tct, relin_keys) |
| 49 | t7 = time.perf_counter() |
| 50 | |
| 51 | print(f"encode avg: {(t1 - t0) / iter_count * 1000:.3f} ms") |
| 52 | print(f"encrypt avg: {(t3 - t2) / iter_count * 1000:.3f} ms") |
| 53 | print(f"decrypt avg: {(t5 - t4) / iter_count * 1000:.3f} ms") |
| 54 | print(f"square+relin avg: {(t7 - t6) / iter_count * 1000:.3f} ms") |
| 55 | print(f"memory pool allocated bytes: {MemoryManager.GetPool().alloc_byte_count()}") |
| 56 | |
| 57 | |
| 58 | def bench_ckks(iter_count=10): |
no test coverage detected