import sys
sys.path.append('/Users/thatch/code/sre_yield_thatch')
import fastdivmod
reload(fastdivmod)
import time
import math
# divmod_iter gives you the moduli when divided by 256 here (right to left)
list(fastdivmod.divmod_iter(sys.maxint, 256))
a = sys.maxint**10000
b = 10**1024
t0 = time.time()
a_ = a
while a_:
mod = a_ % b
a_ = a_ / b
t1 = time.time()
print t1 - t0
# but that's cheating, we can get a 2x speedup by just using divmod
# ... anyone know why? yell it out.
t0 = time.time()
a_ = a
while a_:
a_, mod = divmod(a_, b)
t1 = time.time()
print t1 - t0
print "Gur / naq % bcrengbef ner abj qrsvarq va grezf bs qvizbq(). AHYY pna or cnffrq sbe cqvi be czbq, va juvpu pnfr gung cneg bs gur erfhyg vf fvzcyl guebja njnl.".decode('rot-13') + ' (in longmodule.c)'
t0 = time.time()
for i in fastdivmod.divmod_iter(a, b):
pass
t1 = time.time()
print t1 - t0
# hey guess what it's the same (look in fastdivmod.py)
# switches when < ~1000 iterations to divmod(), and we only have...
print "base **", math.log(a, b)
b = 2
a = b ** 100000
print math.log(a, 256), "bytes"
print "base **", math.log(a, b)
t0 = time.time()
a_ = a
while a_:
a_, mod = divmod(a_, b)
t1 = time.time()
with_divmod = t1 - t0
print with_divmod
t0 = time.time()
for i in fastdivmod.divmod_iter(a, b):
pass
t1 = time.time()
with_fastdivmod = t1 - t0
print with_fastdivmod
print "speedup %.02fx" % (with_divmod/with_fastdivmod,)