aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/sca
diff options
context:
space:
mode:
authorJ08nY2021-11-27 16:09:27 +0100
committerJ08nY2021-11-27 16:09:27 +0100
commit4c0dd490280c88a54ab7e493907dfb5e8b8eefbf (patch)
tree13529b50b9768bd9c82584fa5685f1f1e77db262 /test/sca
parent69f6a0bd10d76d72da799bb22132e8555bc13dd3 (diff)
downloadpyecsca-4c0dd490280c88a54ab7e493907dfb5e8b8eefbf.tar.gz
pyecsca-4c0dd490280c88a54ab7e493907dfb5e8b8eefbf.tar.zst
pyecsca-4c0dd490280c88a54ab7e493907dfb5e8b8eefbf.zip
Add profiling of sca.combine submodule.
Diffstat (limited to 'test/sca')
-rw-r--r--test/sca/perf_combine.py49
-rw-r--r--test/sca/test_rpa.py4
2 files changed, 52 insertions, 1 deletions
diff --git a/test/sca/perf_combine.py b/test/sca/perf_combine.py
new file mode 100644
index 0000000..9b934d7
--- /dev/null
+++ b/test/sca/perf_combine.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python
+import click
+
+from test.utils import Profiler
+from pyecsca.sca import (
+ InspectorTraceSet,
+ average,
+ variance,
+ standard_deviation,
+ add,
+ subtract,
+ conditional_average,
+)
+
+
+@click.command()
+@click.option("-p", "--profiler", type=click.Choice(("py", "c")), default="py")
+@click.option("-o", "--operations", type=click.INT, default=100)
+@click.option(
+ "-d",
+ "--directory",
+ type=click.Path(file_okay=False, dir_okay=True),
+ default=None,
+ envvar="DIR",
+)
+def main(profiler, operations, directory):
+ traces = InspectorTraceSet.read("test/data/example.trs")
+ with Profiler(profiler, directory, f"combine_average_example_{operations}"):
+ for _ in range(operations):
+ average(*traces)
+ with Profiler(profiler, directory, f"combine_condavg_example_{operations}"):
+ for _ in range(operations):
+ conditional_average(*traces, condition=lambda trace: trace[0] > 0)
+ with Profiler(profiler, directory, f"combine_variance_example_{operations}"):
+ for _ in range(operations):
+ variance(*traces)
+ with Profiler(profiler, directory, f"combine_stddev_example_{operations}"):
+ for _ in range(operations):
+ standard_deviation(*traces)
+ with Profiler(profiler, directory, f"combine_add_example_{operations}"):
+ for _ in range(operations):
+ add(*traces)
+ with Profiler(profiler, directory, f"combine_subtract_example_{operations}"):
+ for _ in range(operations):
+ subtract(traces[0], traces[1])
+
+
+if __name__ == "__main__":
+ main()
diff --git a/test/sca/test_rpa.py b/test/sca/test_rpa.py
index 1f06e92..995099d 100644
--- a/test/sca/test_rpa.py
+++ b/test/sca/test_rpa.py
@@ -65,7 +65,9 @@ class MultipleContextTests(TestCase):
self.assertListEqual(muls, [1, 2, 3, 5])
def test_window(self):
- mult = WindowNAFMultiplier(self.add, self.dbl, self.neg, 3, precompute_negation=True)
+ mult = WindowNAFMultiplier(
+ self.add, self.dbl, self.neg, 3, precompute_negation=True
+ )
with local(MultipleContext()):
mult.init(self.secp128r1, self.base)
mult.multiply(5)