[pypy-commit] pypy improve-rbigint: Speedup floordiv by the power of two
stian
noreply at buildbot.pypy.org
Sat Jul 21 18:41:14 CEST 2012
Author: stian
Branch: improve-rbigint
Changeset: r56327:0d3da1111129
Date: 2012-06-24 22:30 +0200
http://bitbucket.org/pypy/pypy/changeset/0d3da1111129/
Log: Speedup floordiv by the power of two
diff --git a/pypy/rlib/rbigint.py b/pypy/rlib/rbigint.py
--- a/pypy/rlib/rbigint.py
+++ b/pypy/rlib/rbigint.py
@@ -412,6 +412,15 @@
return div
def floordiv(self, other):
+ if other.numdigits() == 1 and other.sign == 1:
+ digit = other.digit(0)
+
+ if digit == 1:
+ return self
+ elif digit & (digit - 1) == 0:
+ div = self.rshift(ptwotable[digit])
+ return div
+
div, mod = self.divmod(other)
return div
diff --git a/pypy/translator/goal/targetbigintbenchmark.py b/pypy/translator/goal/targetbigintbenchmark.py
--- a/pypy/translator/goal/targetbigintbenchmark.py
+++ b/pypy/translator/goal/targetbigintbenchmark.py
@@ -10,6 +10,7 @@
"""
A cutout with some benchmarks.
Pypy default:
+ 5.147583
484.5688
334.611903
8.637287
@@ -21,6 +22,7 @@
6.647562
Pypy with improvements:
+ 2.307890
9.451896
1.122038
5.787821
@@ -32,6 +34,14 @@
6.434917
"""
+
+ t = time()
+ num = rbigint.fromint(100000000)
+ for n in xrange(80000000):
+ rbigint.floordiv(num, rbigint.fromint(2))
+
+
+ print time() - t
t = time()
num = rbigint.fromint(10000000)
More information about the pypy-commit
mailing list