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

Поделиться
HTML-код
  • Опубликовано: 21 авг 2024
  • Which free scientific computing language is the fastest to program and execute? The answer probably won't surprise you because it's obvious.

Комментарии • 283

  • @taragnor
    @taragnor 2 года назад +579

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

    • @xmdi0
      @xmdi0  2 года назад +98

      agreed. if anyone has some ideas for fair benchmarks, let me know. something that can be implemented relatively quickly without non-standard libraries

    • @evertonsantosdeandradejuni3787
      @evertonsantosdeandradejuni3787 2 года назад +3

      My thoughts exactly

    • @evertonsantosdeandradejuni3787
      @evertonsantosdeandradejuni3787 2 года назад +2

      @@xmdi0 No Ideias, but please do. Alredy clicked on the Bell Icon

    • @dmitriidemenev5258
      @dmitriidemenev5258 2 года назад +3

      @@xmdi0 Rust is meant to be used with non-standard libraries (=crates). My personal favorite for benchmarking is criterion.

    • @dilgarda
      @dilgarda 2 года назад

      @@xmdi0 Also include a simple I/O operation. I really wonder the capability of reading and writing capabilities.

  • @bartl9798
    @bartl9798 2 года назад +25

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

  • @coleshores
    @coleshores 2 года назад +135

    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.

    • @JalenThompson0
      @JalenThompson0 2 года назад +13

      I’d like to think he’s being sarcastic

    • @deidyomega
      @deidyomega 2 года назад +18

      Yeah, I write python, and I hit a math problem, I drop to C, write a lib, the expose the .so file in python and keep working. Simple, effective, and get to keep my high productivity in python.

    • @Luxalpa
      @Luxalpa 2 года назад +1

      You just confirmed that it would be cheating. If you're using it wrong for high performance computing (which I agree with) then it would also be wrong to measure it's performance to begin with.

    • @deidyomega
      @deidyomega 2 года назад +4

      @@Luxalpa I do agree measuring its preformace for algros is wrong. I dont know any devs who spend their time in python writing algros like that. We are building large applications with 100's of dependances and 100k+ loc. When you hit that size, what matters is developer read speed, not compile time, and honestly.. not even run time. I mean, we gotta keep the hot path fast, but again 99% of the time for me at least, its the network thats the bottleneck, not the application.

    • @Jack-hd3ov
      @Jack-hd3ov 2 года назад +4

      It's cheating if you're comparing Python as a language to another language like C or Fortran, which is what's happening in this video. Sure you might be able to get better performance using Python with libs written in a faster language than you could with straight Python but that doesn't make Python fast, you get good performance because the language used to write the library is faster than Python.

  • @FR33Willi
    @FR33Willi 2 года назад +65

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

    • @pedromiguelareias
      @pedromiguelareias 2 года назад +1

      Not even a chance. Fortran and C++, that's it. All the rest is a passing fashion.

    • @FirstLast-kv1iq
      @FirstLast-kv1iq 2 года назад

      @@pedromiguelareias lol do you have brain damage?

    • @DoctorMandible
      @DoctorMandible 6 месяцев назад +2

      @@pedromiguelareias That's hilarious. Nvidia is building a multi-billion AI business that runs entirely on Python.

    • @pedromiguelareias
      @pedromiguelareias 6 месяцев назад +5

      @@DoctorMandible Python just makes use of C, C++ and Fortran libraries. It's a wrapper and inefficient at that.

    • @Designed1
      @Designed1 26 дней назад

      @@pedromiguelareias at that point just say that all programming languages except C is useless since they are all based off of C anyway

  • @niconeuman
    @niconeuman 2 года назад +73

    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.

    • @danielthirtle666
      @danielthirtle666 2 года назад +5

      So Octave is the fastest language if you write all of your code in C++?

    • @paperclips1306
      @paperclips1306 Год назад +1

      ​@@danielthirtle666 hahaha

    • @ZackDia-Ptr
      @ZackDia-Ptr Год назад

      Thought Octave is just a library... xD

    • @goose_clues
      @goose_clues Год назад

      Is "using C++ is easy for scientists" some kind of joke, or this person is.

    • @niconeuman
      @niconeuman Год назад

      @@goose_clues you are talking about my comment? Because it says the opposite of what you are implying

  • @saitaro
    @saitaro 2 года назад +38

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

    • @Rau379
      @Rau379 Год назад

      Hi Sataro, why for-loop over the matrix is misusing of the library? Is there another way to reach each component of the matrix with numpy?

    • @danial_amini
      @danial_amini 23 дня назад

      in the second numpy code he avoided the loops with native np/matmul commands

    • @ShinjiCarlos
      @ShinjiCarlos 11 дней назад +1

      Using Numpy is either using Fortran or C in the backend. :/

  • @7th_CAV_Trooper
    @7th_CAV_Trooper 2 года назад +31

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

  • @julianmahler2388
    @julianmahler2388 2 года назад +12

    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.

    • @dimi5862
      @dimi5862 Год назад +4

      So, your point is python is slower?

    • @danial_amini
      @danial_amini 23 дня назад

      fortran is faster than even c++ tho but yes when I try to measure speed in python with jit I just put the timer around the function itself to exclude the "compile" time.

  • @ondraodehnal1250
    @ondraodehnal1250 2 года назад +34

    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.

    • @saitaro
      @saitaro 2 года назад +16

      Man, the author thinks using numpy (or even importing it as np) is cheating, for Numba you go to jail lol

    • @klittlet
      @klittlet 2 года назад

      @@saitaro the test involves using the languages by themselves

    • @saitaro
      @saitaro 2 года назад +2

      @@klittlet I got it, but if he decides to use numpy (which is not a part of the Python stdlib), then it should be done properly, not for-looping over the np.array. It's just wrong to write Python code in the style of Fortran, and vise-versa.
      IMHO, in the end, comparative tests should be about using tools from whole ecosystem of the language. It is especially important for scripting languages like Python.

    • @danial_amini
      @danial_amini 23 дня назад

      @@saitaro he didn't for loop, he used numpy and matmul tho. But if you use cython I think you'll go back to loops apparently.

  • @ianbridges6040
    @ianbridges6040 2 года назад +20

    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.

    • @theairaccumulator7144
      @theairaccumulator7144 2 года назад +6

      Should've used c++

    • @deidyomega
      @deidyomega 2 года назад +5

      Fortran is a very challenging language. C/C++ would give you about equal results, with way less screaming into the void. There's a reason basically no one uses fortran anymore.

    • @theairaccumulator7144
      @theairaccumulator7144 2 года назад +4

      @@deidyomega C++ would probably give you much better results if you used multithreading and a sane linear algebra library which implements SIMD. It would probably solve all those equations within a second.

    • @klittlet
      @klittlet 2 года назад

      @@deidyomega yeah no

    • @deidyomega
      @deidyomega 2 года назад

      @@klittlet Are you disagreeing with the fact people dont use fortran anymore? Or that its challenging? Or that C/C++ have comparable results?
      All of those can be backed up pretty easily.

  • @GenTheSnail
    @GenTheSnail 2 года назад +12

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

  • @niyaziugur
    @niyaziugur 2 года назад +12

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

    • @LoL-ox8li
      @LoL-ox8li 2 года назад

      12 like almısın nıyazi

    • @adreto2978
      @adreto2978 Месяц назад

      Fortran wins

  • @sydelcid
    @sydelcid 2 года назад +7

    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

    • @SuperSulc
      @SuperSulc 2 года назад +5

      Your results are meaningless without the other two solutions or at least the specs of the system.

    • @danial_amini
      @danial_amini 23 дня назад

      @@SuperSulc the results aren't meaningless, numpy uses a single core and the single core performance of various x86 CPUs (old vs new) are relatively comparable.

  • @shayhan6227
    @shayhan6227 2 года назад +12

    You should include the Version of python and python libraries you used to allow for watchers far in the future to compare and benchmark against it so they can understand the progress made over the years.

  • @wangzhang2686
    @wangzhang2686 2 года назад +8

    most biased video against python I've ever seen. especially when I saw A.__sub__. Not to mention np.eye and np.abs v.s. np.identity and np.absolute.

  • @michaelmonkenbusch5591
    @michaelmonkenbusch5591 2 года назад +6

    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}')

  • @TheUser357
    @TheUser357 2 года назад +4

    I don’t know, maybe there are beginners to whom such videos are somehow useful, but in fact a normal developer knows very well that each programming language has its own advantages, purposes of application and best coding practices.
    What's the point of comparing airplane, lorry and tractor on what is the faster to go for grocery shopping to a nearby store?
    Dislike from me.

  • @spiderjerusalem
    @spiderjerusalem 2 года назад +14

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

    • @taoliu3949
      @taoliu3949 2 года назад +1

      Speed is still important. What could take days on FORTRAN may take weeks to compile and run. That's why it's still king in certain industries like Physics where you need to crunch high amounts of data.

  • @matela6635
    @matela6635 2 года назад +17

    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.

    • @m0zzar353
      @m0zzar353 11 месяцев назад

      time to import libraries is still time that the code takes to run. part of the beauty of a language like fortran is that it needs no libraries for mathematical computation no?

  • @Fritzinat0r
    @Fritzinat0r 2 года назад +5

    You sir have done the needful

  • @unknown3158
    @unknown3158 2 года назад +9

    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++).

    • @xmdi0
      @xmdi0  2 года назад +3

      this 100%. in my experience matlab is usually 2-10x faster than octave, but there are ways to compile octave yourself to build in some of these (intel?) accelerations. something i have never needed to do, but i read about once

    • @dickpiano1802
      @dickpiano1802 2 года назад +2

      There is a technical term for that. Implementations in MATLAB/Python/Octave need to be "vectorized".
      If you are writing C in MATLAB/Python/Octave then you shouldn't be using MATLAB/Python/Octave.

  • @swan4959
    @swan4959 2 года назад +6

    Java vs C# vs python

  • @VladimirTheAesthete
    @VladimirTheAesthete 2 года назад +4

    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.

  • @mustafa-gokce
    @mustafa-gokce 2 года назад +15

    Well, Python results like that because you did it wrong :)

  • @OM222O
    @OM222O 2 года назад +3

    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.

  • @trafalgarla
    @trafalgarla 2 года назад +5

    There's Julia too, but it's JIT compilation takes a few seconds the first time you run a program.

    • @benjlung
      @benjlung 2 года назад +1

      Pretty sure Julia would win in programming time (assuming the author is similarly experienced in all languages). In run-time, Julia would be a close battle with Fortran if you include compilation time in both languages or none. Even if including compilation time, Julia should be faster than Python and Octave here.

    • @danial_amini
      @danial_amini 23 дня назад

      I also tried jit numba in python and yes it does take a while to load the first time. I don't know how to do multithreading with it tho.

  • @julienpepin6
    @julienpepin6 2 года назад +5

    wouldn't it be cooler to add compiling time into the trace ? like, a potential language which is written like python/octave but compiles to the same bytes as fortran would blow up this comparison..

    • @Jupiter__001_
      @Jupiter__001_ 20 дней назад

      No, because compilation is not usually done at runtime, whereas interpretation must always happen at runtime.

  • @shimadabr
    @shimadabr Год назад +1

    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

  • @arsgorrussia477
    @arsgorrussia477 2 года назад +7

    Great channel! I think you have a good potential in growing the auditory.
    Greetings from Russia)

  • @user-vs6kc9xu4r
    @user-vs6kc9xu4r 2 года назад +3

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

  • @richdelgado3405
    @richdelgado3405 2 года назад +2

    I used to program in Fortran and Cobol. Eventually, the SQL app tools started coming out and people would just laugh at the "old school" languages like Cobol.
    Then they tried to use their fancy new db tools to process a few hundred thousand records. I could go through them in a few minutes. Their SQL just slowly chugged along.

    • @sycration
      @sycration 2 года назад

      There are some pretty fast ORMs out there (I have some experience with Diesel) but I usually return to using SQL 😁

  • @LouisChiaki
    @LouisChiaki 2 года назад +2

    The person clearly type much slower in python even for the same code and same amount of characters...

  • @agustinpizarro
    @agustinpizarro 2 года назад +3

    You are missing an important metric, how much time you spent learning those languages to do useful work.

    • @misterbalise
      @misterbalise 2 года назад

      it is not the purpose of this video ;)

  • @topec1263
    @topec1263 2 года назад +1

    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.

  • @marcusunivers
    @marcusunivers 2 года назад +2

    This Keyboard ASMR is so satisfying xD

  • @Techiesse
    @Techiesse 2 года назад +2

    You shouldn't print anything in the middle of the benchmark. IO is very slow and doesn't make sense during the calculation

  • @severgun
    @severgun 2 года назад +2

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

    • @stevy2
      @stevy2 2 года назад +2

      Actually makes me happy I use NodeJS. It trades blows with Java when it comes to speed.

  • @dedebenui
    @dedebenui 2 года назад +1

    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

  • @manuelsuazo1125
    @manuelsuazo1125 2 года назад +6

    U need try compiler optimizations for fortran.
    -O3 and -Ofast.
    gfortran -Ofast nn.f94

  • @SmPro1337
    @SmPro1337 2 года назад

    Cool content. Found you through my recommended videos. Earned my sub.

  • @stevenwilson5556
    @stevenwilson5556 2 года назад +5

    So Fortran smokes modern languages for things that Fortran is good at doing. What about things that Fortran isn't good at doing? It seems like the speed and efficiency of Fortran wins where Fortran is able to do things, but I'm sure there are a myriad of use-cases where Fortran can't even do certain types of things.
    Python isn't the most popular programming language due to efficiency and speed, but because it is easy and approachable to learn how to code in it, and it can do a whole lot of different things reasonably well. And with modern computer hardware, the differences in speed shown in these tests won't show up in many day-to-day tasks.
    Just my 2c.

    • @pedromiguelareias
      @pedromiguelareias 2 года назад +1

      Fortran is very simple. Implementation times are unbeatable and compile times are way faster than those of C++.

  • @felenov
    @felenov 2 года назад +2

    We need to see Haskell and Lisp, the father of all evil languages,

  • @michaelgolub2019
    @michaelgolub2019 2 года назад +2

    The results are quite predictable. Interpreters work slower, but in general require less time for coding. Python unlike Octave/MATLAB or Fortran is a multipurpose language, so it may be slower in all aspects. The more interesting could be comparison of outputting a graph (Fortran has no intrinsic graph tools). I use Fortran for many decades, used MATLAB for some time and sometimes use Octave and gnuplot. I have some basic info about Python and responses from those how use it.

  • @eclair1616
    @eclair1616 Месяц назад

    No. Assembly was the first programming language. In fact assembly is the human readable alternative of machine code. It is machine code. Fortran is the first language to have a compiler that then converts to assembly.

  • @donharrold1375
    @donharrold1375 Год назад

    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.

  • @necroorcen
    @necroorcen Год назад

    That looping over numpy array made my eyes 🩸

  • @meinkea
    @meinkea 2 года назад +2

    First of, did like the video
    However, 1:20 rubs me the wrong way.
    In the real world, the ecosystem of libraries at your disposal is likely more important the the language itself.
    Any comparison where you are not taking that into account might be entertaining but is not really informative to make a conclusive decision of which is faster.
    In the end languages are standards and what you are comparing are implementations of that standard, not the language.
    If there is a specialized Linear Algebra library that shreds through your task, you use it (regardless it be Python or Fortran)
    If using Python lowers the bar for a user to use said library, its fair game and should be concidered.
    If fortran has a exotic but useful Lin Alg library with hand assembly optimization, its fair game and should be considered.
    Maybe try making a video comparing these implementations where your leveraging these libraries?

  • @aaaaa-yv1zr
    @aaaaa-yv1zr 2 года назад +1

    Demo 2 on Matlab 2021b, run time is 0.026 s.
    tic
    for i=1:10
    n=200;
    A=rand(n,n);
    [L,U]=lu(A);
    norm(L*U-A,Inf);
    end
    toc

  • @manuelpena3988
    @manuelpena3988 2 года назад +1

    why do you use A.__sub__(...) instead of A - ... ?

  • @mechconsultingmechconsulti4284
    @mechconsultingmechconsulti4284 Год назад +1

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

  • @hasanhanzalah9799
    @hasanhanzalah9799 2 года назад +1

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

  • @pocztowka2
    @pocztowka2 2 года назад +1

    you should also measure a time of other co-worker sit watching the code and thinking "what the heck it does?"

  • @_Mr.9-5
    @_Mr.9-5 2 года назад +1

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

    • @xmdi0
      @xmdi0  2 года назад

      Just a vertical window on my desktop. Would be cool to have a phone app for that - especially for traveling. If you find a good one, let me know.

    • @_Mr.9-5
      @_Mr.9-5 2 года назад

      @@xmdi0
      java n ide
      I want learning java but i don't have PC so i learn in this app idk this is good? I think your knowledge more than mine

  • @flaguser4196
    @flaguser4196 2 года назад

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

  • @elchippe
    @elchippe 2 года назад +5

    That is no cheating, using scipy library is not cheating. Using cython, numba or pypy is. And numba is not C, but an LLVM compiler for python.

    • @nikolageorgiev2341
      @nikolageorgiev2341 2 года назад +1

      It technically is cheating because most of the heavy calculation functions in SciPy are written in C/C++/Fortran. And when you compare how fast a language can crunch numbers, making that language run a program written in another language to do the hard work is def cheating. But Python isn't made to be a fast number crunching programming language so the comparison is pretty pointless anyway.

  • @snarbywrx
    @snarbywrx Год назад

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

  • @shivakumarnatrajan
    @shivakumarnatrajan 2 года назад

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

  • @anarchistalhazen7084
    @anarchistalhazen7084 2 года назад +2

    If I want to learn an auxiliary lang to python for scientific computing, should I go with C or Fortran?

    • @xmdi0
      @xmdi0  2 года назад +2

      C will be easier to learn for you because there are more resources, and it's more similar to Python. The main advantage to Fortran is that all this matrix algebra stuff is baked in, whereas you need a library or your own data structures to do that stuff in C.

    • @anarchistalhazen7084
      @anarchistalhazen7084 2 года назад

      @@xmdi0 Ty, indeed I did not find as good and many resources for FORTRAN, but I thought it had an inheritant advantage over C or something. But is reading files really that slow in FORTRAN? (which could be a different comparison vid)

    • @Labicraft
      @Labicraft 2 года назад

      I'd say Fortran, although the language is quite awful everybody in science (at least physics) uses it if they are not going for python (I never used it but I guess it must have tons of libraries?).

    • @idiosinkrazijske.rutine
      @idiosinkrazijske.rutine 2 года назад

      Both

    • @Alche_mist
      @Alche_mist 2 года назад +1

      @@Labicraft It really has a ton of well optimized libraries and is quite possible to understand if you come from other scientific background than computer science (which can't be said in all honesty about C or C++ when you need the amount of control typically needed in physics for huge calculations). Basically, it takes away some of the most notorious footguns from the coder.
      That said, I'd also like to draw attention to Julia, which is a language specifically made to make the number crunching typically done in physics and statistics easier to both write and execute (similar to Fortran, but with a more modern look and options).

  • @MarkWernsdorfer
    @MarkWernsdorfer 2 года назад +1

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

    • @rupen42
      @rupen42 Год назад +1

      Not if you use it wrong and iterate through the values with a for loop, apparently.

  • @georgerogers1166
    @georgerogers1166 2 месяца назад

    Julia would be interesting especially with more computationally intensive work.

  • @PiroKUSS
    @PiroKUSS 2 года назад

    It was nice hearing the keystrokes.

  • @idk____idk6530
    @idk____idk6530 2 года назад +2

    Use Cython bro then see the speed ☣️

  • @jff4131
    @jff4131 2 года назад +1

    numpy+for?

  • @Orincaby
    @Orincaby 2 года назад +2

    "free knockoff matlib thing"
    -xmdi 2021

  • @whamer100
    @whamer100 2 года назад

    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

    • @xmdi0
      @xmdi0  2 года назад +1

      Definitely true.

  • @simonbode7356
    @simonbode7356 2 года назад +1

    Fortran does produce the fatsest executable.

  • @superJerrySong
    @superJerrySong 2 года назад +2

    please make a epic fight beetween javascript and python or java vs C++*_*

  • @bobpetersen6136
    @bobpetersen6136 2 года назад +1

    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

  • @miguel-oi5uz
    @miguel-oi5uz 2 года назад +1

    recommend learning fortran in 2022?

    • @justasydefix6251
      @justasydefix6251 2 года назад +1

      are you an engineer? are you a mathematician? If not fortran might be of little use for you. If Yes, Then you probably needs to buy Matlab after all...

    • @miguel-oi5uz
      @miguel-oi5uz 2 года назад

      @@justasydefix6251 I am studying computer engineering

  • @shis10
    @shis10 2 года назад +1

    Python vs R vs Ruby

  • @ZackDia-Ptr
    @ZackDia-Ptr Год назад

    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

  • @vanlee6643
    @vanlee6643 11 месяцев назад

    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?

    • @xmdi0
      @xmdi0  11 месяцев назад +1

      I can confirm for you that Fortran is still used in academia, particularly in aerospace engineering, but long gone are the days that engineers actually seem to care about writing fast programs themselves. I see more people either using scripting languages or specialized software to solve their problems, instead of writing the code themselves.

  • @mithrillis
    @mithrillis 2 года назад +3

    I think the performance comparison is not meaningful unless you run a task that will at least take the fastest language a few minutes. Otherwise we are just comparing some constant overhead.

  • @gustavderkits8433
    @gustavderkits8433 Год назад

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

  • @georgerogers1166
    @georgerogers1166 11 месяцев назад

    Julia is another good one for comparison.

  • @cow_tools_
    @cow_tools_ Год назад

    Love the attitude.

  • @playstationrussia2515
    @playstationrussia2515 4 месяца назад

    If someone is trying to prove you that "python is not slow11!!1!11!1!1 Just use... C libraries!!!". Is that C vs Octave vs Fortran comparison? No. The out-of-the-box methods should be used for every language you test. Python is slow, you'll have to live with it. No matter how fast it COULD be.

  • @idunnu7242
    @idunnu7242 2 года назад +1

    C is no 1 !!!!!

  • @mpotane
    @mpotane 2 года назад +14

    Python is slow when used incorrectly. It's quite rare to see nested loop in python even coding challenges / interview. Python coding is searching a module/ package, use its methods then solve the problem. You do not use numpy directly in Python.

    • @eltravos
      @eltravos 2 года назад +5

      1:40

    • @TheDEFCHER
      @TheDEFCHER 2 года назад

      Интересно как избавиться от вложенного цикла в этой задаче и какой будет от этого смысл?

    • @unknown3158
      @unknown3158 2 года назад +3

      Wait, what do you mean by "You do not use numpy directly in Python."? Pretty sure I've had to use Numpy in my projects many times, and there was no alternative. Also, Python is good and preferred because you can write the code very quickly and you don't really need to spend much time typing or thinking about what to type. If you actually need to make the code much more complex just to make sure it runs faster, you're better off using a compiled language. In other words, it's not always about being used "incorrectly", sometimes using it "correctly" makes the code too complex and takes too much time.

    • @TheDEFCHER
      @TheDEFCHER 2 года назад

      ​@@unknown3158 поддерживаю. Нет смысла доказывать, что Pyton может быть таким же как и С/C++ (почти таким же) потому, что он *не* должен быть как C/C++

    • @TrueAlexCv
      @TrueAlexCv 2 года назад

      Python is slow always

  • @alio263
    @alio263 2 года назад

    Which language should I learn as an absolute beginner?

    • @FR33Willi
      @FR33Willi 2 года назад +1

      My opinion: pick Python if you want programming to be complimentary to your job, pick Java if you want your job to be a full-time software engineer. The most important thing is to just get started though, it doesnt really matter what you pick.

    • @alio263
      @alio263 2 года назад

      @@FR33Willi I have started with HTML and CSS for doing simple websites, once i end those i think im going with java or javascript

  • @m_a_s6069
    @m_a_s6069 5 месяцев назад

    Why not look at Julia?

  • @zweiwing4435
    @zweiwing4435 Год назад

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

  • @abrahammiranda2329
    @abrahammiranda2329 7 месяцев назад

    Is there someone who knows here how to start programming in Fortran, I need it please. I mean, which compiler could you suggest me, thanks in advance.

  • @olgierd245
    @olgierd245 2 года назад

    I LOVE THESE

  • @geovanniportilla7159
    @geovanniportilla7159 2 года назад

    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 ;).

  • @shayhan6227
    @shayhan6227 2 года назад +1

    Can you do a Rust vs C or Rust vs C++ or C++ vs NodeJS vs Python?

    • @Luxalpa
      @Luxalpa 2 года назад +1

      C++ vs NodeJS vs Python? Why even make this comparison? We already know C++ is fastest, then NodeJS and slowest will be Python.

    • @shayhan6227
      @shayhan6227 2 года назад

      @@Luxalpa Unfortunately while I agree with you, I've had to debate with people on which was faster and I would like to set a hard benchmark to settle all debates.

    • @nishanth6403
      @nishanth6403 2 года назад

      @@shayhan6227 lmao

  • @thaddaeusmarkle1665
    @thaddaeusmarkle1665 2 года назад

    At 1:54 what with python how do you get those parens to add themselves. You're obviously using vim, is that a plugin or a custom config thing?

    • @trianglesupreme
      @trianglesupreme 2 года назад

      lol

    • @FunOrange42
      @FunOrange42 2 года назад +1

      i'm pretty sure he's typing them manually, just looking at the parens highlight to know when to stop typing

  • @JDahl-sj5lk
    @JDahl-sj5lk 2 года назад

    Python is by design just objects. Well, objects is a nice way of saying it is pointers to everything. (pointers to pointers to data or even more pointers) Then on top of that it isn't compiled and it's very rich in built in features.
    Python is a nice scripting language; but i think it should have optional curly brackets by default. Why?
    Cause the argument that you wouldn't use python in a situation where you cant easily control whitespace indent is only true because you can't use curly brackets.
    It is precisely in small scripts i just want to send to an interpreter i could use something like python.
    I know and have used semicolons to mark newline, f.ex if you ever need to use eval() , and it's possible but way to difficult.
    But python does have some uses where speed isn't any major concern, altough i might change that statement if/when i get well into JavaScript. Still, python is a nice language to start with, it's sort of the modern basic.
    I didn't know Fortran was much used anymore though, remember it was one of the first languages i dabbled with.

  • @sr_meia_noite
    @sr_meia_noite 2 года назад +1

    That moment when .__sub__()

  • @lennutrajektoor
    @lennutrajektoor 2 года назад

    Octave is re-branded Basic?

  • @TheZethera
    @TheZethera 2 года назад

    Would be interesting to see R in there

  • @TheZethera
    @TheZethera 2 года назад

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

  • @playbyan1453
    @playbyan1453 2 года назад

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

  • @givdb5513
    @givdb5513 2 года назад

    I can't believe you just wrote "sped"👈 not "speed"👈

  • @kantocoder5046
    @kantocoder5046 2 года назад

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

  • @heretixseven7732
    @heretixseven7732 2 года назад

    Can you do that in C too? Compare?

  • @gordonfreeman4357
    @gordonfreeman4357 2 года назад

    What language is vim interface in?

  • @luistorres5805
    @luistorres5805 2 года назад

    what is the name of the application

  •  2 года назад +2

    Julia?

  • @yanceq2690
    @yanceq2690 2 года назад

    Im subbing, do more things like this please