Py 3 slower than Py 2. Towers of Hanoi implementation
Stefan Behnel
stefan_ml at behnel.de
Fri Jun 26 10:14:50 EDT 2009
Udyant Wig wrote:
> I implemented this -> http://www.apl.jhu.edu/~hall/lisp/Hanoi.lisp in
> both flavors of Python: 2.6.2 and 3.0.1 (CPython)
>
> The code:
> #!/usr/bin/env python
> def remaining_peg (peg1, peg2):
> return (6 - peg1 - peg2)
>
> def hanoi (num_discs, start, end):
> if (1 == num_discs):
> print "Top of peg {0} to peg {1}".format(start,end) # used print()
> for Py 3.0.1
>
> else:
> hanoi ((num_discs - 1), start, (remaining_peg (start, end)))
> hanoi (1, start, end)
> hanoi ((num_discs - 1), (remaining_peg (start, end)), end)
>
>
> hanoi(20,2,3)
>
> The times: real usr sys
> Python 2.6.2 7.994s 3.336s 3.296s
> Python 3.0.1 55.302s 38.024s 5.876s
>
> What happened to Python?
Have you tried Python 3.1? Have you made sure that both Python interpreters
were build with the same compiler arguments and that none of them is a
debug build?
Stefan
More information about the Python-list
mailing list