From 3a13c0b8941d8a2f05b9db5e7d2a55558165e723 Mon Sep 17 00:00:00 2001 From: Benoit Chevallier-Mames Date: Mon, 27 Sep 2021 18:19:01 +0200 Subject: [PATCH] test: add x - 24 in benchmark, doesn't compile refs #471 --- benchmarks/x_minus_24.py | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 benchmarks/x_minus_24.py diff --git a/benchmarks/x_minus_24.py b/benchmarks/x_minus_24.py new file mode 100644 index 000000000..16e711f8a --- /dev/null +++ b/benchmarks/x_minus_24.py @@ -0,0 +1,43 @@ +# Target: x - 24 + +import random + +import concrete.numpy as hnp + + +def main(): + def function_to_compile(x): + return x - 24 + + x = hnp.EncryptedScalar(hnp.UnsignedInteger(6)) + + # Measure: Compilation Time (ms) + engine = hnp.compile_numpy_function( + function_to_compile, + {"x": x}, + [(i,) for i in range(2 ** 6)], + ) + # Measure: End + + inputs = [] + labels = [] + for _ in range(4): + sample_x = random.randint(40, 40 + 2 ** 3 - 1) + + inputs.append([sample_x]) + labels.append(function_to_compile(*inputs[-1])) + + correct = 0 + for input_i, label_i in zip(inputs, labels): + # Measure: Evaluation Time (ms) + result_i = engine.run(*input_i) + # Measure: End + + if result_i == label_i: + correct += 1 + + # Measure: Accuracy (%) = (correct / len(inputs)) * 100 + + +if __name__ == "__main__": + main()