[pypy-commit] pypy improve-rbigint: Fix a test and add some benchmarks for pow, mul and add operations.

stian noreply at buildbot.pypy.org
Sat Jul 21 18:41:02 CEST 2012


Author: stian
Branch: improve-rbigint
Changeset: r56316:9fe5555f3c53
Date: 2012-06-22 03:54 +0200
http://bitbucket.org/pypy/pypy/changeset/9fe5555f3c53/

Log:	Fix a test and add some benchmarks for pow, mul and add operations.

diff --git a/pypy/rlib/rbigint.py b/pypy/rlib/rbigint.py
--- a/pypy/rlib/rbigint.py
+++ b/pypy/rlib/rbigint.py
@@ -864,7 +864,7 @@
         if digit == 0:
             return rbigint([NULLDIGIT], 1)
         elif digit == 1:
-            return rbigint([b._digits[0]], 1)
+            return rbigint(b._digits[:], 1)
         
     size_b = b.numdigits()
 
diff --git a/pypy/translator/goal/targetbigintbenchmark.py b/pypy/translator/goal/targetbigintbenchmark.py
new file mode 100644
--- /dev/null
+++ b/pypy/translator/goal/targetbigintbenchmark.py
@@ -0,0 +1,78 @@
+#! /usr/bin/env python
+
+import os, sys
+from time import time
+from pypy.rlib.rbigint import rbigint
+
+# __________  Entry point  __________
+
+def entry_point(argv):
+    """
+        A cutout with some benchmarks.
+        Pypy default:
+        18.270045
+        2.512140
+        14.148920
+        18.576713
+        6.647562
+
+        Pypy with improvements:
+        15.211410
+        1.707288
+        13.955348
+        14.474590
+        6.446812
+
+    """
+    t = time()
+    
+    for n in xrange(10000):
+        rbigint.pow(rbigint.fromint(n), rbigint.fromint(10**4))
+        
+
+    print time() - t
+    
+    t = time()
+    
+    for n in xrange(100000):
+        rbigint.pow(rbigint.fromint(1024), rbigint.fromint(1024))
+        
+
+    print time() - t
+    
+    
+    t = time()
+    v = rbigint.fromint(2)
+    for n in xrange(50000):
+        v = v.mul(rbigint.fromint(2**62))
+        
+
+    print time() - t
+    
+    t = time()
+    v2 = rbigint.fromint(2**8)
+    for n in xrange(28):
+        v2 = v2.mul(v2)
+        
+
+    print time() - t
+    
+    t = time()
+    v3 = rbigint.fromint(2**62)
+    for n in xrange(500000):
+        v3 = v3.add(v3)
+        
+
+    print time() - t
+    
+    return 0
+
+# _____ Define and setup target ___
+
+def target(*args):
+    return entry_point, None
+
+if __name__ == '__main__':
+    import sys
+    res = entry_point(sys.argv)
+    sys.exit(res)


More information about the pypy-commit mailing list