summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYesudeep Mangalapilly <yesudeep@gmail.com>2011-08-12 13:12:06 +0530
committerYesudeep Mangalapilly <yesudeep@gmail.com>2011-08-12 13:12:06 +0530
commit3780830bae12d3f2f6f6145eb62727cadf734928 (patch)
tree24b40269222d279bd6d4041df140ce1ec1505c8d
parentb7341b658d6d2285676ce0b3c287383ad69a293e (diff)
downloadrsa-3780830bae12d3f2f6f6145eb62727cadf734928.tar.gz
Completes machine-aligned int2bytes implementation.
* This implementation is generally in microseconds instead of milliseconds, which makes it 20x-40x faster than the older implementation. Tests for all of the behavior of the function have been added to tests/test_transform.py. Hope this helps make python-rsa even better. =)
-rw-r--r--rsa/transform.py9
-rwxr-xr-xspeed.sh3
2 files changed, 12 insertions, 0 deletions
diff --git a/rsa/transform.py b/rsa/transform.py
index 5318dbf..c0f458e 100644
--- a/rsa/transform.py
+++ b/rsa/transform.py
@@ -21,6 +21,15 @@ From bytes to a number, number to bytes, etc.
from __future__ import absolute_import
+try:
+ # We'll use psyco if available on 32-bit architectures to speed up code.
+ # Using psyco (if available) cuts down the execution time on Python 2.5
+ # at least by half.
+ import psyco
+ psyco.full()
+except ImportError:
+ pass
+
import binascii
from struct import pack
from rsa import common
diff --git a/speed.sh b/speed.sh
index a9a1431..a2c4014 100755
--- a/speed.sh
+++ b/speed.sh
@@ -13,4 +13,7 @@ python2.7 -mtimeit -s'from rsa.transform import _int2bytes; n = 1<<4096' '_int2b
echo "python3.2"
python3 -mtimeit -s'from rsa.transform import int2bytes; n = 1<<4096' 'int2bytes(n)'
python3 -mtimeit -s'from rsa.transform import _int2bytes; n = 1<<4096' '_int2bytes(n)'
+echo "pypy"
+pypy -mtimeit -s'from rsa.transform import int2bytes; n = 1<<4096' 'int2bytes(n)'
+pypy -mtimeit -s'from rsa.transform import _int2bytes; n = 1<<4096' '_int2bytes(n)'