2to3 used in the Shootout

Discussion in 'Python' started by bearophileHUGS@lycos.com, Dec 23, 2008.

  1. Guest

    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
     
    , Dec 23, 2008
    #1
    1. Advertising

  2. Terry Reedy Guest

    wrote:
    > 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.
     
    Terry Reedy, Dec 23, 2008
    #2
    1. Advertising

  3. Isaac Gouy Guest

    On Dec 23, 11:51 am, wrote:
    > 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〈=pyt...



    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



    > 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
     
    Isaac Gouy, Dec 23, 2008
    #3
  4. Guest

    On Dec 23, 5:21 pm, Isaac Gouy <> wrote:
    > On Dec 23, 11:51 am, wrote:
    >
    > > 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〈=pyt...

    >
    > 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
    >
    > > 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

    >
    >

    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>
     
    , Dec 29, 2008
    #4
  5. Isaac Gouy Guest

    On Dec 29 2008, 8:36 am, wrote:
    > On Dec 23, 5:21 pm, Isaac Gouy <> wrote:
    >
    > > On Dec 23, 11:51 am, wrote:

    >
    > > > They have translated the Python benchmarks of theShootoutsite from
    > > > Py2 to Py3 using 2to3:

    >
    > > >http://shootout.alioth.debian.org/u32/benchmark.php?test=all〈=pyt...

    >
    > > 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

    >
    > > > 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

    >
    > 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
     
    Isaac Gouy, Jan 2, 2009
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robin Becker

    2to3.py download

    Robin Becker, Feb 12, 2008, in forum: Python
    Replies:
    0
    Views:
    678
    Robin Becker
    Feb 12, 2008
  2. Guilherme Polo

    Re: 2to3.py download

    Guilherme Polo, Feb 12, 2008, in forum: Python
    Replies:
    0
    Views:
    981
    Guilherme Polo
    Feb 12, 2008
  3. Helmut Jarausch

    2to3 bug and question

    Helmut Jarausch, Jun 23, 2008, in forum: Python
    Replies:
    2
    Views:
    263
    Terry Reedy
    Jun 23, 2008
  4. Helmut Jarausch

    [2to3] Bug converting import

    Helmut Jarausch, Jun 23, 2008, in forum: Python
    Replies:
    1
    Views:
    249
    Christian Heimes
    Jun 23, 2008
  5. 2to3 Help?

    , Jan 15, 2009, in forum: Python
    Replies:
    14
    Views:
    2,900
Loading...

Share This Page