From b58ac57d42e62ed0137784b5ba8bcf69a475b972 Mon Sep 17 00:00:00 2001 From: Dwayne Litzenberger Date: Sun, 21 Apr 2013 23:51:33 -0700 Subject: pct-speedtest.py: Test the random module --- pct-speedtest.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'pct-speedtest.py') diff --git a/pct-speedtest.py b/pct-speedtest.py index bd099ce..027a87f 100644 --- a/pct-speedtest.py +++ b/pct-speedtest.py @@ -60,6 +60,9 @@ try: except AttributeError: urandom = get_random_bytes +from Crypto.Random import random as pycrypto_random +import random as stdlib_random + class Benchmark: def __init__(self): @@ -105,6 +108,16 @@ class Benchmark: sys.stdout.write("%.2f %s\n" % (value, units)) sys.stdout.flush() + def test_random_module(self, module_name, module): + self.announce_start("%s.choice" % (module_name,)) + alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" + t0 = time.time() + for i in range(5000): + module.choice(alphabet) + t = time.time() + invocations_per_second = 5000 / (t - t0) + self.announce_result(invocations_per_second, "invocations/sec") + def test_pubkey_setup(self, pubkey_name, module, key_bytes): self.announce_start("%s pubkey setup" % (pubkey_name,)) keys = self.random_keys(key_bytes)[:5] @@ -299,6 +312,12 @@ class Benchmark: if hasattr(hashlib, 'sha384'): hashlib_specs.append(("hashlib.sha384", hashlib.sha384)) if hasattr(hashlib, 'sha512'): hashlib_specs.append(("hashlib.sha512", hashlib.sha512)) + # stdlib random + self.test_random_module("stdlib random", stdlib_random) + + # Crypto.Random.random + self.test_random_module("Crypto.Random.random", pycrypto_random) + # Crypto.PublicKey for pubkey_name, module, key_bytes in pubkey_specs: self.test_pubkey_setup(pubkey_name, module, key_bytes) -- cgit v1.2.1