summaryrefslogtreecommitdiff
path: root/utils/benchmark.py
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2017-10-25 10:00:26 +0200
committerMichał Górny <mgorny@gentoo.org>2017-10-25 10:00:26 +0200
commit574879859ab0003d3158dd8fbbcc0645c775eaa9 (patch)
tree3c110957459a66fe900f9f5660c121f43da181b8 /utils/benchmark.py
parentd0151cbf800a916ec61bce8f3473f6ebea171b90 (diff)
downloadgemato-574879859ab0003d3158dd8fbbcc0645c775eaa9.tar.gz
Add the benchmark utility that was used to test threading in hash
Diffstat (limited to 'utils/benchmark.py')
-rwxr-xr-xutils/benchmark.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/utils/benchmark.py b/utils/benchmark.py
new file mode 100755
index 0000000..1003c1a
--- /dev/null
+++ b/utils/benchmark.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+
+import os.path
+import sys
+import timeit
+
+sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
+
+import gemato.hash
+
+
+def benchmark_one(path, hashes):
+ f = lambda: gemato.hash.hash_path(path, hashes)
+ t = timeit.repeat(f, number=1)
+ print("{} -> {}".format(hashes, t))
+
+
+def benchmark(path, hash_sets):
+ if not hash_sets:
+ hash_sets = [
+ ["sha256"],
+ ["sha256", "blake2b"],
+ ["sha256", "blake2b", "sha512"],
+ ]
+ else:
+ hash_sets = [x.split() for x in hash_sets]
+
+ for hashes in hash_sets:
+ benchmark_one(path, hashes)
+
+
+if __name__ == '__main__':
+ if len(sys.argv) < 2:
+ print('Usage: {} <test-file> [<hash-set>...]'.format(sys.argv[0]))
+ sys.exit(1)
+
+ benchmark(sys.argv[1], sys.argv[2:])