diff options
author | skdltmxn <supershop@naver.com> | 2020-06-17 06:12:50 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-16 17:12:50 -0400 |
commit | b3c72d1e4554b5fd58cbf3ba2fbf56275446447b (patch) | |
tree | 613f42672a715b8fa9422a86af09abec66e4fcef /tools/hash_benchmark.py | |
parent | b8872cd303584b28c0d6250184e4a1205bf2ad9b (diff) |
feat(std/hash): reimplement all hashes in WASM (#6292)
Diffstat (limited to 'tools/hash_benchmark.py')
-rw-r--r-- | tools/hash_benchmark.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tools/hash_benchmark.py b/tools/hash_benchmark.py new file mode 100644 index 000000000..8dd3ccf0b --- /dev/null +++ b/tools/hash_benchmark.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python +# Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. +# Performs benchmark on hash algorithms + +import os +import sys +import time +import subprocess + +algorithms = [ + "md5", + "sha1", + "sha224", + "sha256", + "sha512", + "sha3-224", + "sha3-256", + "sha3-384", + "sha3-512", +] + + +def run_benchmark(deno_exe, method, input_file): + # compile + subprocess.call([deno_exe, "run", "cli/tests/hash.ts"]) + + for alg in algorithms: + args = [ + deno_exe, "run", "--allow-read", "cli/tests/hash.ts", method, alg, + input_file + ] + + p = subprocess.Popen(args, stdout=subprocess.PIPE) + (out, _) = p.communicate() + + elapsed = out.split(':')[1].strip() + print "[{}] {}".format(alg, elapsed) + + +def main(): + if len(sys.argv) < 4: + print "Usage ./tools/hash_benchmark.py path/to/deno method input" + sys.exit(1) + + run_benchmark(sys.argv[1], sys.argv[2], sys.argv[3]) + + +if __name__ == '__main__': + main() |