ไม่สามารถเล่นวิดีโอนี้
ขออภัยในความไม่สะดวก

Python Speed Comparison: Faster Than We Thought?!

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ส.ค. 2024
  • Today we compare Python's execution speed with that of Java, C, Go, R and JavaScript, to determine, which language is the fastest or the slowest. When considering all aspects, the results might surprise you.
    Bixly: bixly.com/nn
    ◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
    📚 Programming Books & Merch 📚
    🐍 The Python Bible Book: www.neuralnine...
    💻 The Algorithm Bible Book: www.neuralnine...
    👕 Programming Merch: www.neuralnine...
    🌐 Social Media & Contact 🌐
    📱 Website: www.neuralnine...
    📷 Instagram: / neuralnine
    🐦 Twitter: / neuralnine
    🤵 LinkedIn: / neuralnine
    📁 GitHub: github.com/Neu...
    🎙 Discord: / discord
    🎵 Outro Music From: www.bensound.com/
    Timestamps:
    (0:00) Intro
    (0:22) Bixly
    (1:27) Simple Task Comparison
    (12:12) Complex Task Comparison
    (23:13) Outro

ความคิดเห็น • 104

  • @1Richmar
    @1Richmar ปีที่แล้ว +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

    • @davia.sampaio8633
      @davia.sampaio8633 9 หลายเดือนก่อน +2

      Gold comment

    • @LithiumDeuteride-6
      @LithiumDeuteride-6 9 หลายเดือนก่อน

      For the first test, you can apply a simple formula: sum = (n * n + n)/2 while taking into account the condition i

    • @CheeseStickzZ
      @CheeseStickzZ 7 หลายเดือนก่อน

      Geeks, bruv

  • @veroxsity2336
    @veroxsity2336 ปีที่แล้ว +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 ปีที่แล้ว +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 ปีที่แล้ว +8

      He is probably on the grind when he goes off camera

    • @sadf1416
      @sadf1416 ปีที่แล้ว +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 ปีที่แล้ว

      @@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 ปีที่แล้ว

      @@sadf1416 no he couldn’t

  • @tips1483
    @tips1483 ปีที่แล้ว +28

    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 ปีที่แล้ว +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 11 หลายเดือนก่อน +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 10 หลายเดือนก่อน +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 7 หลายเดือนก่อน +1

      So just use c

  • @AbhishekBM
    @AbhishekBM ปีที่แล้ว +16

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

  • @martingro9352
    @martingro9352 ปีที่แล้ว +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 ปีที่แล้ว

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

    • @dr.rainereschrich1549
      @dr.rainereschrich1549 ปีที่แล้ว +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 ปีที่แล้ว

      Bcz he suck he didnt compile go either lol

    • @nocopyrightgameplaystockvi231
      @nocopyrightgameplaystockvi231 ปีที่แล้ว

      @@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 ปีที่แล้ว +2

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

  • @kamalshkeir
    @kamalshkeir ปีที่แล้ว +6

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

  • @caju84
    @caju84 ปีที่แล้ว +3

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

  • @Zwiesel66
    @Zwiesel66 ปีที่แล้ว +12

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

    • @electra2707_
      @electra2707_ ปีที่แล้ว +6

      3.12 its out with 60% more speed

    • @outofahat9363
      @outofahat9363 ปีที่แล้ว +2

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

  • @nocopyrightgameplaystockvi231
    @nocopyrightgameplaystockvi231 ปีที่แล้ว +6

    3.11 is faster than previous python versions.

  • @mikejohnston9113
    @mikejohnston9113 ปีที่แล้ว +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

  • @SkyFly19853
    @SkyFly19853 ปีที่แล้ว +3

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

  • @sunkanmiotitolaye9354
    @sunkanmiotitolaye9354 ปีที่แล้ว +2

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

  • @grzegorzryznar5101
    @grzegorzryznar5101 ปีที่แล้ว +1

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

  • @alphabasic1759
    @alphabasic1759 ปีที่แล้ว +1

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

  • @Volker-Dirr
    @Volker-Dirr 6 หลายเดือนก่อน

    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.

  • @camsaffari
    @camsaffari 8 หลายเดือนก่อน +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 ปีที่แล้ว

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

  • @dookshi
    @dookshi ปีที่แล้ว +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?

  • @anamoyeee
    @anamoyeee 9 หลายเดือนก่อน

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

  • @dipeshsamrawat7957
    @dipeshsamrawat7957 4 หลายเดือนก่อน

    Excellent! ❤

  • @qbaliu6462
    @qbaliu6462 17 วันที่ผ่านมา

    I think you forgot to recompile the updated go script.

  • @thatmagicalcat
    @thatmagicalcat ปีที่แล้ว +1

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

  • @falklumo
    @falklumo ปีที่แล้ว +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 ปีที่แล้ว

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

    • @falklumo
      @falklumo ปีที่แล้ว +1

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

    • @falklumo
      @falklumo ปีที่แล้ว +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 ปีที่แล้ว

      @@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 ปีที่แล้ว +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 ...

  • @Radical9535
    @Radical9535 ปีที่แล้ว +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 ปีที่แล้ว

      "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 ปีที่แล้ว +1

      @@lengors7327 yes development speed.

  • @LithiumDeuteride-6
    @LithiumDeuteride-6 9 หลายเดือนก่อน

    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 9 หลายเดือนก่อน

      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 9 หลายเดือนก่อน

      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 9 หลายเดือนก่อน

      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

  • @lixiang7349
    @lixiang7349 ปีที่แล้ว +1

    Why don’t you use numpy for python?

  • @serkan_bayram
    @serkan_bayram ปีที่แล้ว

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

  • @aquaeyed82
    @aquaeyed82 10 หลายเดือนก่อน

    wow, thanks for sharing knowledge, subscibed.

  • @NishithSavla
    @NishithSavla ปีที่แล้ว +1

    You should have used hyperfine to benchmark all these

  • @Volker-Dirr
    @Volker-Dirr 6 หลายเดือนก่อน

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

  • @muralir8504
    @muralir8504 ปีที่แล้ว

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

  • @ChimeraGilbert
    @ChimeraGilbert ปีที่แล้ว

    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;
    }

  • @lilcwn
    @lilcwn 9 หลายเดือนก่อน

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

  • @alphabasic1759
    @alphabasic1759 ปีที่แล้ว

    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?

  • @joelmartinez7326
    @joelmartinez7326 10 หลายเดือนก่อน

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

  • @ayoubelmhamdi7920
    @ayoubelmhamdi7920 ปีที่แล้ว

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

  • @RSP13
    @RSP13 2 หลายเดือนก่อน

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

  • @CASnumber
    @CASnumber ปีที่แล้ว

    Bixly interests me thank you

  • @goncaloazevedo9822
    @goncaloazevedo9822 9 หลายเดือนก่อน

    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

  • @betapacket
    @betapacket ปีที่แล้ว

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

  • @woody5012
    @woody5012 ปีที่แล้ว

    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 ปีที่แล้ว

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

  • @idocpp
    @idocpp ปีที่แล้ว

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

  • @Miracle-uc6es
    @Miracle-uc6es ปีที่แล้ว

    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 ปีที่แล้ว

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

  • @xbwafi
    @xbwafi ปีที่แล้ว

    dose vim works in pycharm???

  • @chriskeo392
    @chriskeo392 ปีที่แล้ว

    I want python to one day be faster than C#

  • @sbksdg7019
    @sbksdg7019 ปีที่แล้ว

    wow, really amazing

  • @MirulFahimi
    @MirulFahimi ปีที่แล้ว

    Python 3.11 very fast

  • @willyhorizont8672
    @willyhorizont8672 ปีที่แล้ว

    I love py & js

  • @veroxsity2336
    @veroxsity2336 ปีที่แล้ว

    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

  • @ulrich-tonmoy
    @ulrich-tonmoy ปีที่แล้ว

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

  • @karmylr
    @karmylr ปีที่แล้ว

    Full of loopholes

  • @shanent5793
    @shanent5793 ปีที่แล้ว

    One sample tells us less than nothing

  • @lengors7327
    @lengors7327 ปีที่แล้ว +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

  • @mechwarrior83
    @mechwarrior83 ปีที่แล้ว

    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 ปีที่แล้ว

      Never noticed his mistakes in previous videos?

  • @MrREALball
    @MrREALball ปีที่แล้ว +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 ปีที่แล้ว

      TH-cam was/is written in Python.

    • @demolazer
      @demolazer ปีที่แล้ว

      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.

  • @joelmartinez7326
    @joelmartinez7326 10 หลายเดือนก่อน

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

  • @techiskek
    @techiskek ปีที่แล้ว

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

  • @SonusVolvebatur
    @SonusVolvebatur ปีที่แล้ว

    n 1

  • @consciousbeing7785
    @consciousbeing7785 ปีที่แล้ว +1

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