4 ms·
This kind of benchmark doesn't make sense for Python because it is measuring the speed of pure code written in the language. However, and here is the important
by coliveira 2y ago
This kind of benchmark doesn't make sense for Python because it is measuring the speed of pure code written in the language. However, and here is the important point, most python code rely on compiled libraries to run fast. The heavy lifting in ML code is done in C, and Python is used only as a glue language. Even for web development this is also the case, Python is only calling a bunch of libraries, many of those being written in C.
- igouy 2y agoaka Python is as fast as C when it is C.
- knowitnone 2y agoI don't know. Ruby is able to call C too so it's a wash?
- chucke 2y agoThat's not true. Sure, many hot path functions dealing with tensor calculations are done in numpy functions, but etl and args/results are python objects and functions. And most web development libs are pure python (flask, django, etc)
- coliveira 2y agoFor performance, hot paths are the only ones that matter.
- IshKebab 2y agoSure, but only a small subset of problems have a hot path. You can easily offload huge tensor operations to C. That's the best possible case. More usually the "hot path" is fairly evenly distributed through your entire codebase. If you offload the hot path to C you'll end up rewriting the whole thing in C.
- dragonwriter 2y agoYeah, this is a benchmark of recursion and tight loops doing integer math on array members. Nontrivial recursion is nonidiomatic in Python, and tight loops doing integer math on array members will probably be done via one of the many libraries that do one or more of optimizing, jitting, or move those to GPU (Numpy, Taichi, Numba, etc.)
- int_19h 2y agoAny language with FFI (which is like all of them, these days) has the same exact issue, the only difference being how common it is to drop into C or other fast compiled language for parts of the code. And this kind of benchmark is the one that tells you why this is different across different languages.
- ModernMech 2y agoYes, if you pull out all the optimization tricks for Python, it will be faster than vanilla Python. And yet it's still 6x slower (by my measurement) than naive code written in a compiled language like Rust without any libraries.
- kreetx 2y agoYet this particular blog post shows how Ruby-writen-in-Ruby is faster than Ruby-written-in-C because it's more optimizable.