How to make Python run as fast (or faster) than Julia
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Fri Feb 23 13:05:59 EST 2018
On Fri, 23 Feb 2018 13:51:33 +0000, Ben Bacarisse wrote:
[...]
>> I don't know why the Julia programmers chose to use such a poor
>> algorithm:
>
> It's odd indeed, but given that they did, what you take to be the point
> of the article -- to write a good Python algorithm as fast as the
> terrible Julia one -- seems a bit pointless.
Someone looking at the Julia benchmarks will look at the results and go,
"Wow! Julia is so much faster than Python, I should choose to use Julia
instead!".
But guess what? The benchmarks are flawed. The performance of real-world
Julia code doesn't match the performance of the benchmarks.
"What’s disappointing is the striking difference between
the claimed performance and the observed one. For example,
a trivial hello world program in Julia runs ~27x slower
than Python’s version and ~187x slower than the one in C."
http://zverovich.net/2016/05/13/giving-up-on-julia.html
Admittedly "Hello World" is not what *I* would call a real world program,
but that's just an illustration of the discrepancy between the
performance in artificial benchmarks and the performance in useful code.
The benchmarks emphasise what Julia is good at, and use poor, unidiomatic
Python code. People who are either too naive to know better, or who *do*
know better but for some bizarre reason still take benchmarks at face
value, believe them, and conclude that Julia is faster than Python. Not
just a bit faster, but enough to conclude that Python is uncompetitive.
Okay, so Julia is fast, at least for toy benchmarks, maybe or maybe not
for actual code you care about. Great. Python is fast too, if you stop
writing shitty code. The *FIRST* lesson in optimization is to re-write
your crap implementation with a better algorithm. The point of the post
is to teach that lesson.
Stop writing crap code and then complaining that the language is "too
slow". Write better code, and then we'll take your complaints seriously.
Or, you never know, maybe you'll find it's fast enough and you don't
actually have to abandon your existing code base and migrate to a whole
new language.
"Python takes hours to sort a million integers using BubbleSort! Its too
damn slow!!!"
"Why not use the built-in sort? That's fast."
"NOOOOOO!!!! I MUST USE BUBBLESORT, BECAUSE REASONS!!!1!"
*wink*
--
Steve
More information about the Python-list
mailing list