Pyhon 2.x or 3.x, which is faster?

Chris Angelico rosuav at gmail.com
Mon Mar 7 18:40:31 EST 2016


On Tue, Mar 8, 2016 at 9:39 AM, BartC <bc at freeuk.com> wrote:
>
> What are you suggesting here? That all these Pythons are going to be faster
> or slower than each other? I would guess that most of them are going to be
> roughly the same, other than PyPy. If there was a fast version, then I would
> have heard about it!

Try them, then you'll know. They all have different strengths and weaknesses.

>> the
>> performance of array.array() is far from stable. It's not a core
>> language feature; you're using it because it's the most obvious
>> translation of your C algorithm,
>
> I'm using it because this kind of file reading in Python is a mess. If I do
> a read, will I get a string, a byte sequence object, a byte-array, or
> array-array, or what?

Uhh.... you'll get either a text string or a byte string, depending on
whether you opened the file as text or binary. Where's the mess?

> Are you saying there array.array will not work on some implementations? In
> that case it's more of a mess than I thought!

No, it'll always be there (at least, I'm pretty sure it will). I said
that its *performance* is all over the place. Try coding in the
simplest possible way first, and only turn to array.array afterward.

> Real world use of Python appears to be as a scripting language and for glue
> code, with most of the real work done in libraries implemented in native
> code. I acknowledge that. And I understand that the 10-20% difference
> between Py2 and Py3 will largely disappear for these kinds of uses.

Real world use of Python includes writing full-scale applications in
it... not sure whether the myriad web apps written with
Flask/Django/etc count as "most of the real work done in native
libraries". But what does "real work" mean? When you write a data
processing program in Python, you could spend most of your time doing
integer arithmetic using the native 'int' type, or you could spend
most of your time using numpy. One of those is using a third-party
library written in Fortran; the other is using the language facilities
directly. But in CPython, the latter means you're using C. Where's the
difference? All your most important code - all the "real work" in
terms of algorithms etc - is in Python. The underlying facilities are
completely generic.

> But I also said I am interested in using the languages to directly implement
> programs and algorithms not just for scripting. Then you need to be able to
> measure what the core language is capable of.

Yeah, because the value of human legs is proven by walking from one
city to the next and seeing how long it takes. You're still using the
language inefficiently, and then proving that one inefficient use is
less inefficient than another. Congratulations.

I'm done.

ChrisA



More information about the Python-list mailing list