summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDwayne Litzenberger <dlitz@dlitz.net>2013-04-21 23:51:33 -0700
committerDwayne Litzenberger <dlitz@dlitz.net>2013-04-21 23:51:33 -0700
commitb58ac57d42e62ed0137784b5ba8bcf69a475b972 (patch)
treecb333ed8cb549de980e7e3fc35649e74eae8951c
parent22d7760ae7346d80a6c54b1549e9a1d560c239bc (diff)
downloadpycrypto-b58ac57d42e62ed0137784b5ba8bcf69a475b972.tar.gz
pct-speedtest.py: Test the random module
-rw-r--r--pct-speedtest.py19
1 files changed, 19 insertions, 0 deletions
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)