2to3 used in the Shootout

B

bearophileHUGS

They have translated the Python benchmarks of the Shootout site from
Py2 to Py3 using 2to3:

http://shootout.alioth.debian.org/u32/benchmark.php?test=all&lang=python3

It shows some "performance bugs" of Python3 itself (especially
regarding the binary-trees benchmark, that was unexpected by me), and
two points where 2to3 may be improved, for example after the
translation this gives error:
table=string.maketrans('ACBDGHK\nMNSRUTWVYacbdghkmnsrutwvy',
'TGVHCDM
\nKNSYAAWBRTGVHCDMKNSYAAWBR')):

Gives:
TypeError: maketrans arguments must be bytes objects

Bye,
bearophile
 
T

Terry Reedy

They have translated the Python benchmarks of the Shootout site from
Py2 to Py3 using 2to3:

http://shootout.alioth.debian.org/u32/benchmark.php?test=all&lang=python3

It shows some "performance bugs" of Python3 itself (especially
regarding the binary-trees benchmark, that was unexpected by me), and
two points where 2to3 may be improved, for example after the
translation this gives error:
table=string.maketrans('ACBDGHK\nMNSRUTWVYacbdghkmnsrutwvy',
'TGVHCDM
\nKNSYAAWBRTGVHCDMKNSYAAWBR')):

Gives:
TypeError: maketrans arguments must be bytes objects

Perhaps you could file a tracker item.
 
P

pruebauno

So please re-write those programs to remove problems created by
automatic translation and better take advantage of Python 3
functionality...

http://shootout.alioth.debian.org/u32/faq.php#play
BTW I am not sure how to submit this or if this is actually valid to
do, but I have a faster version for the pidigits program that uses
basically the same algorithm but removes function calls and unused
terms of the formula.

<pre>
import time

def pi_digits(n, width):
out = []
wrt = out.append
aq = 1
ar = 0
at = 1
k = 0
f = 1
g = 2
i = 0
while i < n:
y = (aq*3+ar)//at
while y != ((aq*4+ar)//at):
k += 1
f += 2
g += 4
ar = aq*g+ar*f
aq = aq*k
at = at*f
y = (aq*3+ar)//at
aq = 10*aq
ar = 10*ar-10*y*at
i += 1
wrt(str(y))
if not i%width:
wrt('\t:%d\n'%i)
wrt(' '*(width-i%width))
wrt('\t:%d\n'%i)
return ''.join(out)


def main():
begin = time.time()
n = 1000
width = 70
print pi_digits(n,width)
print 'Total Time:', time.time()-begin

main()

</pre>
 
I

Isaac Gouy

On Dec 23, 11:51 am, (e-mail address removed) wrote:
So please re-write those programs to remove problems created by
automatic translation and better take advantage of Python 3
functionality...

BTW I am not sure how to submit this or if this is actually valid to
do, but I have a faster version for the pidigits program that uses
basically the same algorithm but removes function calls and unused
terms of the formula.

<pre>
import time

def pi_digits(n, width):
    out = []
    wrt = out.append
    aq = 1
    ar = 0
    at = 1
    k = 0
    f = 1
    g = 2
    i = 0
    while i < n:
        y = (aq*3+ar)//at
        while y != ((aq*4+ar)//at):
            k += 1
            f += 2
            g += 4
            ar = aq*g+ar*f
            aq = aq*k
            at = at*f
            y = (aq*3+ar)//at
        aq = 10*aq
        ar = 10*ar-10*y*at
        i += 1
        wrt(str(y))
        if not i%width:
            wrt('\t:%d\n'%i)
    wrt(' '*(width-i%width))
    wrt('\t:%d\n'%i)
    return ''.join(out)

def main():
    begin = time.time()
    n = 1000
    width = 70
    print pi_digits(n,width)
    print 'Total Time:', time.time()-begin

main()

</pre>


http://shootout.alioth.debian.org/u32q/faq.php#play
 

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top