On 29/06/2016 14:35, Chris Angelico wrote:
On Wed, Jun 29, 2016 at 11:24 PM, BartC <b...@freeuk.com> wrote:
I used this little benchmark:

def fn():
    n=0
    for i in range(1000000):
        n+=i

for k in range(100):
    fn()

Add, up the top:

try: range = xrange
except NameError: pass

Otherwise, your Py2 tests are constructing a million-element list,
which is a little unfair.

It made little difference (21 seconds instead of 20 seconds).

But that was on Windows. I remember that Python was much more sluggish on Windows than under Ubuntu on the same machine. (Maybe the Windows version was 32-bits or something.)

Trying it on Ubuntu, Py2 takes 6 seconds (using xrange otherwise it's 9 seconds) , while pypy (2.7) manages 0.35 seconds.

pypy normally excels with such loops, but I recall also that it had some trouble with this particular benchmark, which this version must have fixed.

--
Bartc
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to