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

Steven D'Aprano steve at pearwood.info
Fri Mar 11 00:29:00 EST 2016


On Fri, 11 Mar 2016 06:26 am, Mark Lawrence wrote:

> On 10/03/2016 14:22, BartC wrote:
> 
>>
>> But during development, it doesn't hurt if the dynamic version isn't
>> quite so slow!
>>
> 
> In [1]: import this
> The Zen of Python, by Tim Peters
[...]
> No mention of speed anywhere, but then what does that silly old Tim
> Peters know about anything?

The Zen of Python doesn't say anything about being an argumentative,
obnoxious, annoying zealot either, and yet here we are...

What is your problem? By your aggressive nay-saying, anyone would think that
having a fast, efficient programming language was *actively harmful*. If
Guido announced tomorrow that Python 3.6 will include a gee-whiz new
optimization that makes CPython start up in a quarter of the time and run
five times as quickly with no loss or change of functionality, would you
toss a hissy fit because speed isn't important?

Personally, every time I have to wait five minutes for a timeit script to
run, I wish Python was ten times faster. (Say, best of five, each run takes
a minute.) And I absolutely stand by that: I wish Python were faster
without any loss of functionality. (I also want a pony and a plastic
Buddha.)

Maybe if I could afford a faster computer, I would care less. Maybe if I
cared more, I would decide that Python wasn't the language for me and I
would prefer a language with less functionality and more speed. Either
choice is fine. There's no need to aggressively hassle Bart because he
cares more about speed than Python's dynamic features which he neither uses
nor cares about.

The truth is, most people don't -- most Python code uses very little of the
dynamic features that get in the way of optimizing the interpreter, things
like intentionally shadowing or monkey-patching built-ins, adding
attributes to objects on the fly, or using exec and eval. In my dream
language, I wish that there were a way to tell the compiler "this is code
(function, class, module) is not dynamic, optimize it as much as you can".

Or better still, for the compiler itself to recognise when code is static,
and optimize it. Victor Stinner's FAT Python may be that compiler some day,
and I for one can't wait.




-- 
Steven




More information about the Python-list mailing list