From 1d9570d9fff8d61441582d317e18d51e17577b27 Mon Sep 17 00:00:00 2001 From: Matthew Iversen Date: Mon, 7 Oct 2013 02:01:23 +1100 Subject: [PATCH 1/2] Add a simple profiling script --- profile.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 profile.py diff --git a/profile.py b/profile.py new file mode 100644 index 0000000..89f7016 --- /dev/null +++ b/profile.py @@ -0,0 +1,53 @@ +import os +import cProfile +import sys + +import ed25519 + +help_desc = """ +profile.py [case] [loops] + +Run profiling of ed25519 functions + +case - must be one of: + pub -- generating a public key + sig -- generating a signature + val -- validating a signature + +loop - how many times to repeat test +""" + +seed = os.urandom(32) +data = b"The quick brown fox jumps over the lazy dog" +private_key = seed +public_key = ed25519.publickey(seed) +signature = ed25519.signature(data, private_key, public_key) + +gen_public_key = 'ed25519.publickey(seed)' +gen_signature = 'ed25519.signature(data, private_key, public_key)' +do_validation = 'ed25519.checkvalid(signature, data, public_key)' + +case = { + 'pub': gen_public_key, + 'sig': gen_signature, + 'val': do_validation, +} + +length = 300 +choice = '' + +if len(sys.argv) >= 2: + if sys.argv[1] == '-h' or sys.argv[1] == '--help': + print(help_desc) + exit() + choice = sys.argv[1] +if len(sys.argv) >= 3: + length = int(sys.argv[2]) + +method = case.get(choice, 'val') + +loop = '[%s for _ in range(%d)]' + +print('Running %s, %d times\n' % (case[method], length)) + +cProfile.run(loop % (case[method], length)) From 350d8b5b4ca58c6b7d54fb9c95e0303db0faab02 Mon Sep 17 00:00:00 2001 From: Matthew Iversen Date: Tue, 8 Oct 2013 16:01:59 +1100 Subject: [PATCH 2/2] Correct help text, run if main --- profile.py | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/profile.py b/profile.py index 89f7016..49e2585 100644 --- a/profile.py +++ b/profile.py @@ -1,6 +1,6 @@ import os -import cProfile import sys +import cProfile import ed25519 @@ -9,16 +9,16 @@ Run profiling of ed25519 functions -case - must be one of: - pub -- generating a public key - sig -- generating a signature - val -- validating a signature +case - must be one of: [default: val] + pub -- generating a public key + sig -- generating a signature + val -- validating a signature -loop - how many times to repeat test +loops - how many times to repeat test [default: 300] """ seed = os.urandom(32) -data = b"The quick brown fox jumps over the lazy dog" +data = b"The quick brown fox jumps over the lazy dog" * 20 private_key = seed public_key = ed25519.publickey(seed) signature = ed25519.signature(data, private_key, public_key) @@ -36,18 +36,20 @@ length = 300 choice = '' -if len(sys.argv) >= 2: - if sys.argv[1] == '-h' or sys.argv[1] == '--help': - print(help_desc) - exit() - choice = sys.argv[1] -if len(sys.argv) >= 3: - length = int(sys.argv[2]) +if __name__ == "__main__": + + if len(sys.argv) >= 2: + if sys.argv[1] == '-h' or sys.argv[1] == '--help': + print(help_desc) + exit() + choice = sys.argv[1] + if len(sys.argv) >= 3: + length = int(sys.argv[2]) -method = case.get(choice, 'val') + method = case.get(choice, 'val') -loop = '[%s for _ in range(%d)]' + loop = '[%s for _ in range(%d)]' -print('Running %s, %d times\n' % (case[method], length)) + print('Running %s, %d times\n' % (case[method], length)) -cProfile.run(loop % (case[method], length)) + cProfile.run(loop % (case[method], length), sort='time')