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

Mark Lawrence breamoreboy at yahoo.co.uk
Tue Mar 8 11:09:41 EST 2016


On 08/03/2016 11:09, BartC wrote:
> On 08/03/2016 02:45, Mark Lawrence wrote:
>> On 08/03/2016 01:47, BartC wrote:
>
>>> The Python timing for that file is around 20 seconds, time enough to
>>> read 10000 copies from the disk.
>>>
>>> And a C program reads /and decodes/ the same file from the same disk in
>>> between 0.1 and 0.2 seconds.
>>>
>>
>> So how much of that time is Python startup time, compared to C which is
>> effectively zero?
>
> Virtually zero as well.

Nonsense.

>
> That's if by start-up time you mean how long between invoking Python
> with the name of the main module, executing all the imports and defs in
> the main and imported modules, until it starts properly executing code.
>
> In the jpeg test, perhaps 50ms. And it would not depend on the size of
> the input since the start-up routines won't know that.

How did you obtain that figure?

>
>> Or are you suggesting that C code is always 100 times
>> faster than Python?
>
> This test is one of those where C can clearly do a good job of reducing
> most of it down to a series of tight loops where everything is in
> registers.
>
> But yes, numeric algorithms are generally going to be a magnitude or two
> faster in optimised C, compared with CPython executing pure Python code.
>
> (But I also remember posting a test in comp.lang.c that was faster in
> Python than in C. It involved strings and Python had the edge because it
> used counted strings. A straightforward C version would use
> zero-terminated strings, although it could be speeded up with a bit more
> work.)
>
>  > Of course I'd like to see you write C code 100
>> times faster than Python,
>
> No, it would take longer. But the final result could be run hundreds of
> times a day by millions of people.
>

Which also happens with Python, although I expect that many users aren't 
aware of that fact.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence




More information about the Python-list mailing list