Комментарии:
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…
Julia is another good one for comparison.
Ответить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?
Ответить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.
Ответить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."
Try Fortran against C, C++ or even Pascal...
ОтветитьThat looping over numpy array made my eyes 🩸
Ответить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
ОтветитьLove the attitude.
ОтветитьMatlab is not Octave. They are code compatible, but the engines will run differently on different tasks
Ответить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
ОтветитьCan you do for Rust, Carbon Google, Bun, and Zig?
ОтветитьIt must include C++ and C in this comparison.
ОтветитьWhy not use both? I use Python in a Jupyter notebook and F2Py in Fortran code for CPU intensive calculations.
Ответить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.
Fortran vs c vs rust pls
Ответить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
Ответитьpython vs c/c++ vs golang plz
ОтветитьFortran does produce the fatsest executable.
ОтветитьIt was nice hearing the keystrokes.
Ответить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 ;).
ОтветитьGreat code and when to start a Fortran, generally numpy array slow sadly no other reason using. Fortran is faster.
ОтветитьVery informative. Can you do similar video on C/C++ vs dart vs golang?
ОтветитьAre you coding on phone or something? Is cool if you coding in phone. what app you use
ОтветитьWhat a bunch of very silly comments, both in the video and out.
ОтветитьI like that last comment Don't mess with Fortran....🤩
Ответить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.
Ответить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
ОтветитьJava vs C++
Ответить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.
Ответить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++
Ответитьwhat is the name of the application
Ответить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.
Ответитьcurious whether fortran libraries have caught up with current scientific computing... the speeds look compelling
Ответитьisn't using numpy cheating according to your definition as well?
Ответить"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.
In conclusion, Python is absolute garbage in everything, but its simple, so people keep trying to fit it into every problem. Thanks for watching
ОтветитьDude, I'll help you.
import numpy as np
Don't thank me.
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
Ответить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.
Try to code in FORTRAN IV rather than FORTRAN 95, that would be an experience!
ОтветитьWhich language should I learn as an absolute beginner?
Ответить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.
Ответить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}')
Do Python X Julia
ОтветитьPython is good for prototyping, utils scripting, launch automatization and data pre/post manipulation.
Specific tasks in between must be done using specific tools.
Octave is re-branded Basic?
Ответитьgolang vs .net core vs nodejs / deno
ОтветитьYeah for math Fortran is still one of the best for performance
Ответить