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

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

xmdi

2 года назад

124,544 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Captain Dunsell
Captain Dunsell - 13.11.2023 16:10

What you are exposing the stupidity of comparing runtimes with different languages… use the correct language for the task… on the mainframe we have a model for inter language communication and a common runtime library for all languages including Assembler, unifying them under a common enclave… too bad the commodity PC oses haven’t figured this out yet… and why are they still using pCode generators like Python and Java …

Correct language for the task… if the shop is a cobol shop … don’t use C … and today’s cobol can do everything c can … including pointer manipulation…

Ответить
George Rogers
George Rogers - 22.09.2023 22:31

Julia is another good one for comparison.

Ответить
vanlee
vanlee - 16.09.2023 18:14

Hey I know its been a long time since you posted this. But i want to ask everyone here, is fortran a dying language right now? I am an engineering student, will learning fortran be a waste of time?

Ответить
Don Harrold
Don Harrold - 19.08.2023 22:57

This is really quite interesting. As an engineer what do I want? Something that is easy to program first and foremost. That’s why I use MatLab and Octave. I don’t want to fight the programming language - I want to develop a reliable solution with the least amount of time and effort possible! If standard libraries improve performance and speed up the development of code who cares. I’m not creating code for commercial applications. I use programming to solve problems the way an accountant might use a spreadsheet.

Ответить
Sadegh Mirzaee
Sadegh Mirzaee - 01.06.2023 22:42

First: I use those libs in python. Others use them. Companies use them. Can you stop us/them using it?!
Second: Are you manage your time so strict and accurate and disciplined that the difference between 0.21 and 0.006 (milliseconds) hits your performance so hard?!

What is the point of video either?!

I'm a cheater and I'm ok with it. Why you are not?! Are you a slave of ethics (maybe)!
"If there are legal ways (implemented in the law) that give me the permission to cheat and make more money and become richer, I'm a fool not do that. Period" (The reason not to do that might be it's not in my favorite field or things like that. That is ok. But by exaggerated ethics when there is no harm to anyone. That is pure wrong.)

To be more honest, the video and the comments are not about programming. They shouldn't. This is more about the way we think.

Note that I'm not a fanatic/dogmatic (don't know what is the right word) in Python.

I really don't understand why people spend time to create such videos with such a language like "and that is why you don't mess with Fortran."

Ответить
Mechconsulting Mechconsulting
Mechconsulting Mechconsulting - 25.05.2023 23:17

Try Fortran against C, C++ or even Pascal...

Ответить
necroorcen
necroorcen - 02.05.2023 00:57

That looping over numpy array made my eyes 🩸

Ответить
Gabriel Rabello
Gabriel Rabello - 29.04.2023 01:08

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

Ответить
Cow Tools
Cow Tools - 23.04.2023 01:23

Love the attitude.

Ответить
Gustav Derkits
Gustav Derkits - 09.04.2023 16:25

Matlab is not Octave. They are code compatible, but the engines will run differently on different tasks

Ответить
Zack Dia
Zack Dia - 05.03.2023 17:24

How about Julia vs Fortran vs C++?? And of course we should agree upon which c++ version b/c there are a lot of them ... xD

Ответить
Zwei Wing
Zwei Wing - 05.03.2023 05:43

Can you do for Rust, Carbon Google, Bun, and Zig?

Ответить
koroliev
koroliev - 10.02.2023 12:44

It must include C++ and C in this comparison.

Ответить
snarbywrx
snarbywrx - 23.12.2022 05:03

Why not use both? I use Python in a Jupyter notebook and F2Py in Fortran code for CPU intensive calculations.

Ответить
RoundPiano
RoundPiano - 13.10.2022 05:57

Why are you so angry?

One of the big draws of python is the huge community and the vast number of great packages. To call that cheating is like calling Fortran's static typing cheating.

And yeah, python packages use highly optimized, precompiled C and Fortran. And? That makes zero difference to the programmer, other than making the code run faster. You just have to use the very friendly APIs.

What's the point of the video? Clunky languages made for number crunching are faster at number crunching than general purpose, interpreted, dynamically typed, extremely beginner-friendly languages? So insightful...

Not to mention some people have better things to do with their time than to learn Fortran and C++, which doesn't get factored in your weird typeracer test. If python and its packages work fine for them, what's wrong with that?

This purism doesn't help anyone.

Ответить
Robert Antonioni
Robert Antonioni - 27.09.2022 04:38

Fortran vs c vs rust pls

Ответить
Bob Petersen
Bob Petersen - 05.08.2022 00:35

Perfect… that was absolutely expected. There is a reason why many codes, e.g. for weather forecast, still run in Fortran. If you need a weather forecast for tomorrow, you cannot wait 3 more days until Python or Matlab is done with computation

Ответить
MauGame
MauGame - 02.08.2022 17:54

python vs c/c++ vs golang plz

Ответить
Simon Bode
Simon Bode - 10.05.2022 00:31

Fortran does produce the fatsest executable.

Ответить
Zonnie
Zonnie - 27.04.2022 23:23

It was nice hearing the keystrokes.

Ответить
Geovanni Portilla
Geovanni Portilla - 20.04.2022 14:50

May be you are using Cpython as interpreter. It's much better use pypy for fast speed. It's can posible that with pypy this results were similiar to fortran. Peace ;).

Ответить
playbyan1453
playbyan1453 - 15.04.2022 08:51

Great code and when to start a Fortran, generally numpy array slow sadly no other reason using. Fortran is faster.

Ответить
Hasan Hanzalah
Hasan Hanzalah - 15.04.2022 03:57

Very informative. Can you do similar video on C/C++ vs dart vs golang?

Ответить
qwerty?
qwerty? - 09.04.2022 01:54

Are you coding on phone or something? Is cool if you coding in phone. what app you use

Ответить
Paul Ramasco
Paul Ramasco - 02.04.2022 05:24

What a bunch of very silly comments, both in the video and out.

Ответить
shiva kumar
shiva kumar - 28.03.2022 17:57

I like that last comment Don't mess with Fortran....🤩

Ответить
Epic Noob
Epic Noob - 28.03.2022 10:04

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.

Ответить
whamer100
whamer100 - 27.03.2022 13:47

one thing to add as well, is correct me if im wrong, but i believe writing to stdout can slow a program a decent bit if it's running in a single thread

Ответить
MD SOLAIMAN HOSEN
MD SOLAIMAN HOSEN - 24.03.2022 22:48

Java vs C++

Ответить
Vladimir the Aesthete
Vladimir the Aesthete - 22.03.2022 02:15

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.

Ответить
JoshElGuapo
JoshElGuapo - 27.01.2022 08:46

I spend too long writing a 3 paragraph essay of why python is used but I think the answer is obvious, most people are very aware that calling functions written in C isn't cheating, and (less people would know) working in a FORTRAN code base is an absolute nightmare and there's probably little if any reason to use FORTRAN these days. Unless you're getting down into the electrical engineering side of things, and they're probably using C and Assembly, I wouldn't go lower level than C++

Ответить
Luis Torres
Luis Torres - 14.01.2022 11:59

what is the name of the application

Ответить
Julian Mahler
Julian Mahler - 13.01.2022 14:33

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.

Ответить
Flag User
Flag User - 09.01.2022 21:29

curious whether fortran libraries have caught up with current scientific computing... the speeds look compelling

Ответить
Mark Wernsdorfer
Mark Wernsdorfer - 09.01.2022 14:02

isn't using numpy cheating according to your definition as well?

Ответить
a e
a e - 09.01.2022 12:14

"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.

Ответить
Prototype
Prototype - 08.01.2022 03:00

In conclusion, Python is absolute garbage in everything, but its simple, so people keep trying to fit it into every problem. Thanks for watching

Ответить
vzzniko
vzzniko - 07.01.2022 15:32

Dude, I'll help you.

import numpy as np

Don't thank me.

Ответить
dedebenui
dedebenui - 07.01.2022 11:35

for both octave and python, you could do away without for loops and the code would run much faster. I'm not sure if you're trolling or if you just don't know how to use these languages

Ответить
matela
matela - 07.01.2022 11:04

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.

Ответить
kantocoder
kantocoder - 07.01.2022 03:09

Try to code in FORTRAN IV rather than FORTRAN 95, that would be an experience!

Ответить
Alio 26
Alio 26 - 06.01.2022 00:58

Which language should I learn as an absolute beginner?

Ответить
Topec
Topec - 05.01.2022 21:52

Octave is like that kid when he walks in "I CAN RUN FASTER" and ends up being in last place every year for track & field.

Ответить
Michael Monkenbusch
Michael Monkenbusch - 05.01.2022 20:08

Interesing comparison clip. Fortran is also my favourite language to solve scientific and engineering problems. Partly becuase this was my first and continuously used computer language. In particular the modern enhancements make it an up to date high performanc e computation tool.
Motivated your comparison I tried to check what in practice (also using the python import libraries and having own code or slatec libraries in fortran) could be achieved by python (3.6) vs gfortran:
Problem 1: a nasty integration (using scipy.quad vs. adaptive integration in f90) of sin(1/sqrt(x)) from 0 to X with an accuracy level of 1e-9, X was varied form 1 to 100 in 0.01 steps to accumulate enough time: result python 44sec vs Fortran 0.8sec (corroborating your result).
However, employing numpy to solve a large linear equation problem (rand om coefficients, 100 realisations) compared to the old dgefs (slatec) routines yileds a mixed result:
for a 500x500 matrix fortran wins by a factor of about 2 (2.5sec vs 5sec), for a 1000x1000 matrix pyzhon is slightly faster 21sec vs 25sec and for a 2000x2000 Python (numpy) is faster
90sec vs 3.5 min. Obviously the numpy library uses some parallel processing as can be seen by the CPU usage which yields an advantge compared to the single threaded old dgefs routine. Using modern routines with parallelisation would probably restore the initial factor. Howver, with the compiled numpy code the disadvantage of the interpreted language is largely mitigated for problems where the heavy computing is absorbed by these function. Still I favour Fortran also because of other reasons as strict backward compatibility (can icorporate code from 50 years ago without
problems), clarity (if written properly) .
The latter comparison code fragmets if fortran and python are:

FORTRAN
program testsolve
implicit none
integer, parameter :: n = 2000
double precision :: A(n,n), B(n), X(n)
integer :: i
! for linalg solving: A * X = B
do i=1,100
call random_number(A)
call random_number(B)
call lesolve(A,n,B,n,n,X) ! wrapper for slatec dgefs
B = B - matmul(A,X) ! Check the solution
write(*,*)"Mean deviation(",i,") = ", norm2(B)/n
enddo
end program testsolve

PYTHON:
import numpy as np
import numpy.matlib as ml
import numpy.linalg as la
import random
import time

t1=time.perf_counter()
n=2000
A=ml.zeros([n,n])
B=np.zeros(n)
nr=range(n)
repeat=range(100)
for l in repeat:
A=np.random.rand(n,n)
B=np.random.rand(n)
X=la.solve(A,B)
BX=ml.matmul(A,X)-B
u=np.sqrt(ml.vdot(BX,BX))/n
print(f'try no {l} yields residual error = {u}')

t2=time.perf_counter()
print(' ')
print(f'Python(numpy): timer={t2-t1} sec with problem size={n}')

Ответить
Igor Demetrius Alencar
Igor Demetrius Alencar - 05.01.2022 17:04

Do Python X Julia

Ответить
severgun
severgun - 05.01.2022 16:09

Python is good for prototyping, utils scripting, launch automatization and data pre/post manipulation.
Specific tasks in between must be done using specific tools.

Ответить
lennutrajektoor
lennutrajektoor - 05.01.2022 14:13

Octave is re-branded Basic?

Ответить
Quelqu'un
Quelqu'un - 05.01.2022 13:12

golang vs .net core vs nodejs / deno

Ответить
Berb
Berb - 05.01.2022 10:19

Yeah for math Fortran is still one of the best for performance

Ответить