Python vs Fortran vs Octave (Matlab) side-by-side performance comparison

preview_player
Показать описание
Which free scientific computing language is the fastest to program and execute? The answer probably won't surprise you because it's obvious.
Рекомендации по теме
Комментарии
Автор

You need to do Fortran vs C vs Rust. That'd be an interesting battle to see which comes out on top.

taragnor
Автор

It’s not cheating to use C binded libraries. Languages like python are designed to be used like that as glue languages. If you’re doing high performance computing in pure python you’re the one using it wrong.

coleshores
Автор

"Time to write code" is a really weird benchmark considering you keep erasing mistakes and probably already memorised certain lines in some languages but not others. The fortran code even has more lines than the python code but took less time to write?

Also the python and octave code isn't vectorised, which is the main way to write linear algebra code in these languages and basically solves your 'verbosity' problem. I mean, one advantage python and octave have over fortran is that you don't have to use for loops for everything.

FRWilli
Автор

Just FYI in Octave you can write C++ files and compile them to oct-files which can be called as built-in functions. They will increase the speed of code with many loops. Of course there's no competing with Fortran or C++ but ease of use for scientists/engineers also has its merits.

niconeuman
Автор

Never have I come across a professional programmer that considered any technique that worked cheating.

bartl
Автор

You use numpy and then for-loop over the matrix, this is misusing of the library.

saitaro
Автор

I have no clue about Octave, but in regard to Fortran vs. Python you're comparing a highly optimized (-O3 flag) onetime compiled Fortran code to a Python script that keeps loading the NumPy module each time you run it. Probably 80 % of your Python code's execution time is due to the NumPy module being loaded over and over again. I've made similar speed comparisons between C, badly written Python, "pythonic" Python, Python + NumPy, Cython etc. If you load NumPy once and measure the net execution time (=the time the actual execution takes without loading the module), your code will be marginally slower than C, if at all. Obviously, if you repeat a vacuous comparison of gross execution time (loading module + executing the code) vs. net execution time of a precompiled optimized code ten times in a row, the gap between Python and Fortran grows bigger and bigger.

julianmahler
Автор

FORTRAN was the second language I learned. Glad it's still a thing.

th_CAV_Trooper
Автор

I would LOVE to see a comparison of Julia, Python, Fortran and C++ for this kind of application. Julia is the new kid on the block that people seems pretty excited about

shimadabr
Автор

I respect FORTRAN and you have amazing Vim skills but that is not the way to compare it. This is ok for 30 lines of code but what happens when you are working on a lines of code project where dozens of scientists need to collaborate? No one picks python due to its speed, but due to its easiness-to-code and readability, the very same reason that made FORTRAN popular back in the day.

spiderjerusalem
Автор

Nice comparison but isn't the whole point of vectorized data handling packages like numpy, scipy and pandas is to avoid for loops? I'm not sure how this particular example can be implemented otherwise but iterating over arrays or dataframes is basically going against the spirit of these libraries, something that you do as a last resort.

VladimirTheAesthete
Автор

The fact that you absolutely suck at writing python code probably doesn't help your case. Each language has it's benefits. Python is the fastest for prototyping and rapid development because of dynamic typing and a huge base of scientific libraries. If you really care about runtime, you can create custom C extensions to "cheat". Gives you best of both worlds.

OMO
Автор

I wrote a super scuffed “paper” comparing 2 ways of solving systems of linear equations for school and I used Python to solve all of the 15, 000+ systems… thanks to this video I realize I should’ve just used Fortran.

ianbridges
Автор

You code use elementwise function. Why you use for loops in python and fortran?

ДмитрийМакаревич-уш
Автор

as an embedded engineer, i'm curious for Rust vs C/C++ nowadays.

niyaziugur
Автор

The loop should've been inside the program after imports.
I think it's unfair how you benchmarked octave and python in the second test. Both languages have the overhead of loading the interpreter and Python has also to import the modules which takes a comparatively huge amount of time compared to time it takes to get the actual task done.
That would be more representative of real world use as in real applications the time it takes to finish the task dwarfs that of loading.

matela
Автор

AFAIK Matlab is faster than Octave. Also, I have a simple rule when it comes to Python, if I need to use many for loops to do it (and there is no other way, or it is too complex to implement), then I am better off just using a different language (like C or C++).

unknown
Автор

It's like the cfop roux zz debate except there's objective benchmarks that you can hit (zz is Fortran in this example)

GenTheSnail
Автор

It would be nice to include Python with Numba, which is not really hard to use. Then you might get faster code with Python than Octave and maybe even Matlab.

ondraodehnal
Автор

I got 3.54ms per loop for the scipy code. Also numpy code can be made to avoid for loops as much as possible, it gives 154ms per loop

Scipy code:
%%timeit
import numpy as np
import scipy.linalg as la

n = 200
A=np.random.rand(n, n)
P, L, U=la.lu(A)
print(np.max(np.abs(np.matmul(L, U))))

100 loops, best of 5: 3.54 ms per loop

sydelcid