Python Speed Comparison: Faster Than We Thought?!

Sdílet
Vložit
  • čas přidán 7. 09. 2024

Komentáře • 104

  • @veroxsity2336
    @veroxsity2336 Před rokem +40

    i swear this guy never checks comments and is literally never online in his discord at all. its like he makes a video then goes to narnia

    • @chriskeo392
      @chriskeo392 Před rokem +7

      Yea I don't understand that. The whole point is to get subscribers right? 😂
      Communicating effectively with comments gets you subs.
      He needs to watch tutorials on YouTubing effectively

    • @none_ghost6204
      @none_ghost6204 Před rokem +8

      He is probably on the grind when he goes off camera

    • @sadf1416
      @sadf1416 Před rokem +6

      Who cares? This dude arguably has among the best python videos on the internet. This dude could easily combing cash in at a FANG job but instead provides these videos to us.

    • @veroxsity2336
      @veroxsity2336 Před rokem

      @@sadf1416 yea I understand that but usually when you do tutorials, you should at least see if anyone has problems. That's the whole point of teaching.

    • @lilDaveist
      @lilDaveist Před rokem

      @@sadf1416 no he couldn’t

  • @1Richmar
    @1Richmar Před rokem +15

    With the -Ox compilation option enabled in C++, the code would execute instantly (close to zero) since the compiler would recognize that the variable "sum" is never accessed and has no side effects. Consequently, your code would simply become "int main() {//nothing here}". If your code did access "sum," for example, by printing it out using "cout

  • @tips1483
    @tips1483 Před rokem +27

    You should also mention that other implementations are faster then others, some like PyPy which has a just in time compiler option can optimize code a crazy amount.

  • @NewLondonMarshall
    @NewLondonMarshall Před rokem +7

    This test wasnt fair for Java and Go. Go had the build included in the time when it could have just been running the binary, and Java was not compiled to a .class file so of course it would be much slower in interpreted mode.

  • @leopoldtiotsop
    @leopoldtiotsop Před rokem +7

    It is true that python is slower at execution, but to have high performance, it is often recommended to use built-in functions (programmed in C) like sum in this case. With sum(range(100000000)), the speed will be increased.

    • @tielessin
      @tielessin Před 10 měsíci +1

      I just tried this on Colab and this simple change actually makes the code run 7x faster. It went from taking 15.061 seconds to only 2.147 seconds.

    • @Oeuvre-Bramon
      @Oeuvre-Bramon Před 7 měsíci +1

      So just use c

  • @kamalshkeir
    @kamalshkeir Před rokem +7

    the node js loop benchmark one errored, we didn't get the real result

  • @martingro9352
    @martingro9352 Před rokem +14

    Why are you not compiling the Java code via "javac Main.java" first and after that invoking the interpreter with "java Main"? By simply using "java Main.java" you are actually measuring compile time for generating the byte code plus execution time (you don't do that for your C code).

    • @nocopyrightgameplaystockvi231
      @nocopyrightgameplaystockvi231 Před rokem

      Because C compiles to binaries directly. Java is Code to class then to binary.

    • @dr.rainereschrich1549
      @dr.rainereschrich1549 Před rokem +2

      @@nocopyrightgameplaystockvi231 you could use GraalVM native image to also compile to native code.
      Generally I think benchmarking such low code makes no sence. it give you only a hint of trivial functions. To really do benchmarking you have to go through multiple different processing areas (compute, memory management, IO etc.) and also let all of them run longer times. Else you can hit a "sweet spot" in one of the languages. Also if you compare pre-compiled, runtime languages and just in time compiled you need to at least run them all longer to avoid differences in startup time.

    • @nomadvagabond1263
      @nomadvagabond1263 Před rokem

      Bcz he suck he didnt compile go either lol

    • @nocopyrightgameplaystockvi231
      @nocopyrightgameplaystockvi231 Před rokem

      @@dr.rainereschrich1549 agreed. Although for me compilation never mattered at all, unless you are running something incredibly intensive like over 2M appends to a list, which I once tested myself using Python's List, Numpy arrays and Array types. Guess who was the winner. I actually like more of Data structure based speed tests where Python falls behind most languages unless you start substituting with Cython.

    • @blindshellvideos
      @blindshellvideos Před rokem +2

      because the guy who posts videos on this channel has no idea what he is doing

  • @AbhishekBM
    @AbhishekBM Před rokem +15

    You should've done go build and then execute the binary produced. That would've been faster

  • @caju84
    @caju84 Před rokem +3

    Javascript code was not executed actually. Because you've typed time node.main.js ...and got 'Command not found' error.

  • @nocopyrightgameplaystockvi231

    3.11 is faster than previous python versions.

  • @Zwiesel66
    @Zwiesel66 Před rokem +11

    Would be interesting to see how fast it is with Python 3.11.

    • @electra2707_
      @electra2707_ Před rokem +5

      3.12 its out with 60% more speed

    • @outofahat9363
      @outofahat9363 Před rokem +2

      @@electra2707_ Python 3.11 is 60% faster than 3.10. Python 3.12 is not out yet

  • @sunkanmiotitolaye9354
    @sunkanmiotitolaye9354 Před rokem +2

    How did you customize the windows and Linux terminals with the background images?

  • @mikejohnston9113
    @mikejohnston9113 Před rokem +3

    On my computer I get similar results for the python and C matrix time measurements. If I use -O3 to compile the C program it is 4 times faster than the python version

  • @anamoyeee
    @anamoyeee Před 9 měsíci

    Why did it take so long to not find a command in bash ("node." instead of "node ")

  • @Volker-Dirr
    @Volker-Dirr Před 7 měsíci

    hmm... The last variant is unfair, since you use an external library to do the multiplication. You can do that in (nearly) every other language also and then the other language is also faster in developing/coding.

  • @alphabasic1759
    @alphabasic1759 Před rokem +1

    Completely disagree with the development speed comment. That should be an entirely new metric of productivity. Calling it speed just confuses.

  • @SkyFly19853
    @SkyFly19853 Před rokem +2

    I hope you also talk about Cython, CPython, and other extensions for speed comparison.

  • @grzegorzryznar5101
    @grzegorzryznar5101 Před rokem +1

    There will be one more player in this game. Mojo. Could you make some video about it (with benchmarking)?

  • @camsaffari
    @camsaffari Před 8 měsíci +1

    You mistakenly ran "time node.main.js" instead of "time node main.js". The speed for JS was wrong. Also, Python generates bytecodes. You need to rerun the code to measure the real speed.

  • @rons96
    @rons96 Před rokem

    Very nice video, thank you, and this operator you publish before as the most unknown is really awesome.

  • @thatmagicalcat
    @thatmagicalcat Před rokem +1

    add a `-O3` while compiling c code and see the results

  • @qbaliu6462
    @qbaliu6462 Před měsícem

    I think you forgot to recompile the updated go script.

  • @dookshi
    @dookshi Před rokem +1

    I'm all for Python as a quick devel tool but your comparison to C, unfortunately, is not fair and is even somewhat misleading. At around 14:38 you should change the order of loop nesting from i, j, k to i, k, j and only then report the time. How much faster is it now?

  • @LithiumDeuteride-6
    @LithiumDeuteride-6 Před 9 měsíci

    Faster than assembly language! And at the expense of python and the simplicity of the code. This can also be done in assembler, and the code will be just as simple. You just need to write a macro that implements such a function, it will take some time, but then everything will be as simple as on Python.

    • @LithiumDeuteride-6
      @LithiumDeuteride-6 Před 9 měsíci

      In assembler, I replaced the FPU code with SSE2, and this added speed, it was 460 msec, it became 314 msec.

    • @LithiumDeuteride-6
      @LithiumDeuteride-6 Před 9 měsíci

      This is the code for UASM!
      ;; v0.0
      .686
      .xmm
      .model flat, stdcall
      option casemap:none
      include \masm32\include\windows.inc
      include \masm32\include\kernel32.inc
      includelib \masm32\lib\kernel32.lib
      include msvcrt.inc
      include macros.asm
      .code
      main proc
      local time:sdword, tmp:sdword, i:sdword, j:sdword
      local A:dword, B:dword, R:dword
      mov time, clock()
      ASSUME esi:ptr real8, edi:ptr real8, ebx:ptr real8
      mov A, GlobalAlloc(GPTR, 500*500*8)
      mov B, GlobalAlloc(GPTR, 500*500*8)
      mov R, GlobalAlloc(GPTR, 500*500*8)
      mov esi, A
      mov edi, B
      mov ebx, R
      .for (eax=0, i=eax: i

    • @LithiumDeuteride-6
      @LithiumDeuteride-6 Před 9 měsíci

      It turned out to speed up the code, after all, the assembler is faster than Python, even if some particularly magical libraries are used in this python of yours.
      mov ebx, R
      .for (eax=0: eax

  • @serkan_bayram
    @serkan_bayram Před rokem

    Would you consider local pricing on your books in the future?

  • @falklumo
    @falklumo Před rokem +1

    IMHO, a few things need clarification:
    - The java times include compilation time, unlike C. Also, java gets faster when executing a function more than once, possibly faster than C. Also, javascript gets faster.
    - Like numpy, BLAS libraries can also be used with C or Java.
    - The python syntax is more beginner-friendly but bites back in large projects. Like lack of encapsulation etc.
    Otherwise, good video with some valid points.

    • @nocopyrightgameplaystockvi231
      @nocopyrightgameplaystockvi231 Před rokem

      I don't think you can actually write java bytecode directly

    • @falklumo
      @falklumo Před rokem +1

      @@nocopyrightgameplaystockvi231 javac compiles java, just like gcc compiles C.

    • @falklumo
      @falklumo Před rokem +2

      @@nocopyrightgameplaystockvi231 My java timings, compared to NeuralNine's java command =100%) are:
      - 24.5% (javac; time java)
      - 11.6% (10 iterations to give the hotjava compiler a chance, 10.4% after 100 iterations - C does not get faster when executed repeatedly)
      As the C version in NeuralNine's test looks like being 2x as fast as Java (or is it 4x?), the true performance is the same for C and Java, if not Java is faster.
      My original Java timing (w/o javac, 1 iteration) is:
      real 0m0.299s
      user 0m0.306s
      sys 0m0.037s
      which is faster than C. This is in line with the common understanding that compiled java and C are about equally fast.

    • @nocopyrightgameplaystockvi231
      @nocopyrightgameplaystockvi231 Před rokem

      @@falklumo It does. But the end product of Javac isn't binaries as GCC does. Its a class file which has to be processed again by the interpreter for creating MC and then you can see the output.

    • @falklumo
      @falklumo Před rokem +2

      @@nocopyrightgameplaystockvi231 Actually, javac compiles to a binary just like gcc does. The difference is that the binary code is for a virtual processor, not an X86 or ARM. (Sun Microsystems actually built actual hardware processors once upon a time ;) ) But there should be little to no performance difference for long enough an execution. The technology isn't too different from what Apple does for the M1 with X86 binaries actually. You wouldn't say X86 code on the M1 is interpreted because it is blazingly fast and actually converted into ARM code on the fly ...

  • @Volker-Dirr
    @Volker-Dirr Před 7 měsíci

    Why did you code the c code so complicated? Line 1 and 2 are not needed.

  • @lilcwn
    @lilcwn Před 9 měsíci

    is the @ in python really using that "k" loop too? just curious

  • @Radical9535
    @Radical9535 Před rokem +1

    interesting but did you take into consideration that it may be different process times with bigger programs.? Also, optimization largely depends on how the code is written. optimization is basically the least amount of readable code in a program, as I understand it.

    • @lengors7327
      @lengors7327 Před rokem

      "Optimization is the least amount of readable code in a program" - what? Are you talking about optimizing developement speed? Because otherwise this makes no sense

    • @Radical9535
      @Radical9535 Před rokem +1

      @@lengors7327 yes development speed.

  • @lixiang7349
    @lixiang7349 Před rokem +1

    Why don’t you use numpy for python?

  • @NishithSavla
    @NishithSavla Před rokem +1

    You should have used hyperfine to benchmark all these

  • @dipeshsamrawat7957
    @dipeshsamrawat7957 Před 4 měsíci

    Excellent! ❤

  • @alphabasic1759
    @alphabasic1759 Před rokem

    Why is it that you aren’t initializing the C array in the python using numpy like you are for the Java and the c?

  • @RSP13
    @RSP13 Před 3 měsíci

    So, python is fast, as long as the code actually runs o C++.

  • @ayoubelmhamdi7920
    @ayoubelmhamdi7920 Před rokem

    in c , you are use double instead of int or uint16

  • @joelmartinez7326
    @joelmartinez7326 Před 11 měsíci

    ¿Por qué mejor no lo pruebas con un algoritmo y de ordenamiento o búsqueda?

  • @goncaloazevedo9822
    @goncaloazevedo9822 Před 10 měsíci

    The first task wasn't run for javascript, it failed and you only assessed the time it took to fail. Also, java should be compiled first for a real measurement

  • @muralir8504
    @muralir8504 Před rokem

    can we compare same with 3.9 vs 3.11 i think there should be huge difference

  • @CASnumber
    @CASnumber Před rokem

    Bixly interests me thank you

  • @ChimeraGilbert
    @ChimeraGilbert Před rokem

    I just want to add a few things. If you use PyPy intead of CPython for the code in this video, you'll find that it's actually faster than the C program. But if you used a more optimized algorithm for each of these programs, the C is much faster. The C code would be much faster if you write it like this
    #include
    int main() {
    long long N = 100000000;
    long long sum = (N * (N - 1)) / 2;
    printf("Sum: %lld
    ", sum);
    return 0;
    }

  • @aquaeyed82
    @aquaeyed82 Před 11 měsíci

    wow, thanks for sharing knowledge, subscibed.

  • @xbwafi
    @xbwafi Před rokem

    dose vim works in pycharm???

  • @woody5012
    @woody5012 Před rokem

    You should've built the go binary first... surprised you're not aware of this... "go run" first has to build, then run - so it'll be slower.

  • @alphabasic1759
    @alphabasic1759 Před rokem

    It wasn’t necessary to use the includes in the C programs.

  • @chriskeo392
    @chriskeo392 Před rokem

    I want python to one day be faster than C#

  • @lengors7327
    @lengors7327 Před rokem +1

    Is this guy an amateur pretending to be a professional? Either that or he's trying really hard to "sell" python. I see no other justification for such a terrible video.
    First and foremost, he doesnt write any "warmup" code that would allow some languages to have lower times on the benchmarks. He could then compare that to the version without said "warmup" code and see how large the difference is or isnt.
    Secondly, he does one run and thats it. No averages whatsoever. And to make matters worst, he's measuring compile times, for example, for java. Ridiculous honestly. He's also not using any optimizations for C which is just as ridiculous.
    Finally, I like how he tries to "sell" python at the end by comparing a version using a library to versions of Java and C without library. Yeah, python development speed is faster, but if you use Java and C libraries you can make those languages almost as fast development wise.
    Like c'mon man, at least put some effort into it.
    Edit: he also complete ignores different implementations of interpreters and compilers for each language which can produce very different results. What a joke of a video

  • @betapacket
    @betapacket Před rokem

    9:46 💀bro really did node.main.js LOL

  • @Miracle-uc6es
    @Miracle-uc6es Před rokem

    I understand your points. However, this is Python's fault.
    My opinion is Python should give us to choose of assigning static variables and compile the code.
    The default settings may be dynamic data types and interpreter, I have no problem with that, but that is the exact reason of why Python is slow.
    As a user I would like to have an option to write code like C but in Python syntax (if I need speed), If I do not, then I could write code as the default Python settings. But that should be my choice.
    for example, age is an integer value, the interpreter should not "have to" check in every single time. (By the way it is has to be a positive integer value between (0, 127), if I write that in C, I defined it as char age; So, more optimizations can be made)
    I have no idea about why they do not let us define any static value, static data type and compile my code (Interpreter great while developing but after final product developed, I prefer a compiled program.
    Like.
    const PI = 3.14
    int age = 20

    • @demolazer
      @demolazer Před rokem

      Cython does precisely this without having to learn a huge stack of C syntax.

  • @popsikud
    @popsikud Před rokem

    you don't ran the node script there was a error

  • @veroxsity2336
    @veroxsity2336 Před rokem

    hey neural, theres an issue with your machine learning bot, we think the library is broken but not sure, please can you take a look

  • @willyhorizont8672
    @willyhorizont8672 Před rokem

    I love py & js

  • @MirulFahimi
    @MirulFahimi Před rokem

    Python 3.11 very fast

  • @consciousbeing7785
    @consciousbeing7785 Před rokem +1

    In java it takes just one line:
    IntStream.range(0, 1000000000).sum()

  • @shanent5793
    @shanent5793 Před rokem

    One sample tells us less than nothing

  • @ulrich-tonmoy
    @ulrich-tonmoy Před rokem

    You should also add Rust and yea python is fast but not by default

  • @sbksdg7019
    @sbksdg7019 Před rokem

    wow, really amazing

  • @karmylr
    @karmylr Před rokem

    Full of loopholes

  • @mechwarrior83
    @mechwarrior83 Před rokem

    Only mean to criticise constructively dude, your methodology is severely flawed. You are measuring the compile times along with the execution times. You should be compiling binaries and measuring execution speed of those.

    • @lilDaveist
      @lilDaveist Před rokem

      Never noticed his mistakes in previous videos?

  • @joelmartinez7326
    @joelmartinez7326 Před 11 měsíci

    R. no se escucha mucho como lenguaje de programación de alto nivel, pero me gusta su sintaxis.

  • @MrREALball
    @MrREALball Před rokem +1

    First of all, end-to-end measurement you are doing is completely incorrect. You should've done it inside of your scripts.
    Second, with python it is REALY hard to work on complex projects, since there is no type system (the one python has is a joke), hence the development speed would slow down dramatically as the project grows.
    Not hating on python, I think it is a great language for small projects and scripting.

    • @lilDaveist
      @lilDaveist Před rokem

      CZcams was/is written in Python.

    • @demolazer
      @demolazer Před rokem

      You can create a virtual type system using MyPy. Google and Facebook even developed their own versions of it. It's not going to make execution any faster but it helps a lot in terms of development and working on complex projects.

  • @techiskek
    @techiskek Před rokem

    He’s definitely a Croat that’s living in Germany, looks like Mirko cro cop too

  • @SonusVolvebatur
    @SonusVolvebatur Před rokem

    n 1