Python vs C++ vs Java (Speed Comparison)

Поделиться
HTML-код
  • Опубликовано: 12 дек 2024

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

  • @petemartinez3017
    @petemartinez3017 Год назад +157

    Python is good for scripting and readability but not performance.

    • @gostan2718
      @gostan2718 Год назад +28

      I find it hard to read Python

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

      Pure Python, yes. But there are ways and tricks to speed it up. A lot.

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

      ​@@I_am_Raziel​​do you mean by writing the part that need high performance in c++?

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

      @yetanothergamedevchannel Me, too. I miss the C- style curly brackets.

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

      ​@@I_am_Razielespecially the bunch of compiled libs like numpy

  • @BlueIsLeet
    @BlueIsLeet 10 месяцев назад +63

    The test doesn't account for JVM warm up time.

    • @alessandrorossi1294
      @alessandrorossi1294 6 месяцев назад +4

      Yeah this test doesn't account for JVM warmup time and then counts the entirety of python interpreter warmup time

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

      Depending upon your terminology. JVM "warm up" is not strictly an issue in this case...that happens before the very first instruction happens. Dynamic *_class loading_* is always the largest issue; if you're going to build a java "micro benchmark", always run the test 3 or more times within a loop for the loading and then JIT and similar adaptive optimizations to sort themselves out (no pun). Twice is the minimum, but 3 or more times (I use 5) will help verify the distinction between other spurious system slowdowns and the initial two runs. You discard the first results like it came from the East German judge.

  • @Chris-ty7fw
    @Chris-ty7fw Год назад +47

    The test has an issue as it handicaps java's slow start up time ...
    Java has a horrible start up time as it optimises as it runs, with C++ you provide those optimsations at the start and they are fixed. It will compile its compiled byte code down to assembler only after so many iterations. You can turn those opts off and let the JIT just kick .
    Basically run the Java a lot of times on the same problem (without restart) and it will speed up exponentially when the JIT kicks after a number (configurable) of runs in as your then just running assembler like the compiled C++ which it's written in.
    So on a high speed trading server (trading in micros, timed in nanos) you'd warm Java up before you start trading (a known drawback of java). C++ starts exponentially faster but doesn't learn as it goes on run it in five years it's still optimized as it was.
    You wouldn't use Python at all in this scenario ie anything real time or multithreaded but its very good and just doing general stuff ;-)
    You pays your money you takes yours choice and for the record I can program and use all three.

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

      Correct

    • @screenworks267
      @screenworks267  11 месяцев назад +2

      that makes a lot of sense, thanks for the info

    • @aniketbisht2823
      @aniketbisht2823 11 месяцев назад +5

      "C++ doesn't learn as it goes", well compilers keep getting new optimizations. Also the C++ compilers have more knowledge of the whole program at compile time to make better decisions especially if you use header-only libraries and templates. And for optimizing on some data, there's a thing called profile guided optimization.
      And if you really care about latency then you would look at the assembly generated for the specific code path you're concern with (with tools like Compiler Explorer) and not rely on the almighty JVM.

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

      ​@@aniketbisht2823 Read the original comment again

    • @Chris-ty7fw
      @Chris-ty7fw 10 месяцев назад

      @@aniketbisht2823
      "well compilers keep getting new optimizations" - they do and the C++ applications Java compiler and Java virtual machine make use of these easily by moving up java versions but I meant in this case while the code runs, it can/will compile to assember just in time and profile itself against a real run. With java you could profile against some data but it can also profile and adjust itself as it runs as well. The "almighty JVM" by the way is a very nicely written C++ application you should look at the code it's really nice.

  • @simoncowell1029
    @simoncowell1029 Год назад +22

    My 2,300 - line C program compiles in 2 seconds using GCC via Codeblocks, on a laptop that was a mid-range personal use product 6 years ago. Why is it so fast, compared with this little program here ?

    • @rudrakshmishra2761
      @rudrakshmishra2761 Год назад +8

      C is like dressing up Assembly in a tuxedo. There's not much hidden in C when compared to other languages. (Think of format specifiers and how no other language really needs them but C does). It's also blazzingly fast because it communicates to the hardware directly without spending much time abstracting stuff.

    • @BlueIsLeet
      @BlueIsLeet 10 месяцев назад +1

      too many factors that go into compile time for C programs to know

    • @bradleywang289
      @bradleywang289 10 месяцев назад +1

      C is the fastest

    • @yancgc5098
      @yancgc5098 6 месяцев назад

      @@bradleywang289 Assembly is theoretically faster than C

  • @MikeM-ps1kn
    @MikeM-ps1kn 8 месяцев назад +1

    @Screen Works: A suggestion to improve the reliability of the comparison: Increase the amount of samples by several orders of magnitude. Currently, the results are prone to suffering from jitter, as the CPU load on a system varies. Secondly, run the code multiple times in a row and keep the lowest result. C++ is compiled AOT where as the JVM uses JIT. In its current form, the test only tells you about the performance of the first run. Although some commentators here enjoy ranting about the JVM/JIT, it optimizes the code quite aggressively up to the point where it can outperform C++ in certain cases like this simple bubble sort algorithm. That's another story for complex programs, of course, garbage collection takes its toll and cannot compete with optimized memory management in C++

  • @NewLondonMarshall
    @NewLondonMarshall 7 месяцев назад +3

    I love how python wasn't even compiled and it took more than 1/3rd the time to 'compile' than C++. What a slow language

  • @ninadmahalle1647
    @ninadmahalle1647 5 месяцев назад +1

    Did you optimize the code According to language

  • @being_aslam_tiger
    @being_aslam_tiger Год назад +8

    Compare it with C# 11

  • @Timely-ud4rm
    @Timely-ud4rm 10 месяцев назад +2

    Can you do c++ vs Rust? I wanna know which coding language is the fastest and most optimize. Ie meaning it is very optimize to utilize all resource starting up as fast as it can. I think I know the answer C++ but I wanna know if something beats C++

    • @hadrian2801
      @hadrian2801 10 месяцев назад

      Rust

    • @kenarnarayaka
      @kenarnarayaka 8 месяцев назад +2

      Rust often is faster, because unless you find a ton of fast performance libraries, C++ tends to be slower. Rust is also memory-safe, and is way better for web development. The standard rust library is also way faster than C++ standard library, but people have written faster C++ standard libraries like EA Standard Library
      But have fun fighting with the compiler for 7 hours straight lmao

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

      @@kenarnarayaka I fought rust and lost.

  • @vinothm8726
    @vinothm8726 Год назад +5

    Super music and comparison

  • @DinHamburg
    @DinHamburg Год назад +3

    i have never sorted an array with 7 entries.. - and i have sorted *many* arrays...

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

    I know bubble sort is one of the worst non-joke sorting algorithms, but holy shit, >1s to sort a 7 items array is insane

  • @Thisisdcode
    @Thisisdcode 10 месяцев назад +2

    hey atleast c++ was consistent

  • @alta-i9u
    @alta-i9u 4 месяца назад

    i loved the background music. it was like sitting in a piano lounge watching it all unfold on a big screen w a scotch on the rocks.

  • @MarkMcDaniel
    @MarkMcDaniel 2 месяца назад +3

    I don't trust code AI would construct. Write your own code or go away.

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

      I use AI code, but for things like complex 4d vector mathematical functions when I don't have a library at my disposal and when I don't know the math to code that respective function. 80% success rate

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

    Python simplifies the programmer's life a little and drastically worsens the user's life; Python consumes 4x more memory than C++ and is 60x slower in the tests we perform here with various codes.
    Python for those who are not computer scientists even makes sense, to run administrative problems and simple things, prototypes;
    But for computer scientists I don't see the point.
    The great advantage of programming languages ​​is to speed up the USER's life, saving time to carry out their activities. C/C++ does this, optimizing memory and processing time in favor of the user and the environment.
    Python makes it easier for the programmer and slower for users...
    Another point, a program is compiled a few times until we reach the final version. And it will be used thousands of times by thousands of users, so compilation time is only relevant to those who program.
    Once again, attention should be paid to the objective of computer science, which should be to make things easier for the user and not for the programmer.
    First the customer's interest.
    Second, maintain the profession at a high level.

  • @Pyovali
    @Pyovali Год назад +8

    Guess nVidia should write their drivers in Python from now on lol

    • @getforfree8344
      @getforfree8344 Год назад +3

      Python Cant achieve it, its out of the capability of python, infact even out of capability of C++, for low level tasks such as parts of drivers directly interacting with machines low level languages are used which include Assembly or C

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

      ah yes the low level language C@@getforfree8344

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

      @@getforfree8344 C++ can do drivers. A lot of Windows components are written in C++.

    • @shadowofheaven3279
      @shadowofheaven3279 Год назад +2

      I have no idea whether this is satire, because you sound pretty serious

    • @SussyBaka-il1ku
      @SussyBaka-il1ku 10 месяцев назад

      @@getforfree8344 C++ is literally just C (+ predefined functionalities), and is able to do anything C is able to. though, with the tradeoff of compile time and performance.

  • @xerox-f1p
    @xerox-f1p 6 месяцев назад

    What about c#?

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

    JS - what is compilation ?

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

    I was thinking Java was very mutch more slow than C++...

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

    I like the music :P

  • @Swyateg
    @Swyateg Год назад +20

    Java is not for speed from start. Java is for creating secured soft

    • @oktay9784
      @oktay9784 Год назад +19

      It also has the most secure logging tool called 'log4j' lol

    • @hba6018
      @hba6018 Год назад +5

      In fact, it is one of the fastest running languages that exist, thanks to its just-in-time compiler, its optimization and techniques for generating optimized code according to the architecture where the program is being executed. Many people have very old references about Java (like your comment) and have no idea how fast this language is.

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

      @@oktay9784 Its made by apache. WHAT DO U EXPECT? U dont want to send emails using logging lib? U are wierd everyone uses that. And also they are using deprecated stuff so ye good job apache

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

      @@goblinjedly9528 keep calm bro Im just joking

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

      @@oktay9784 Still dont undrestand why would anyone use logging lib

  • @sahazanomenarazafimandimby734
    @sahazanomenarazafimandimby734 6 месяцев назад

    Super, merci pour la comparaison, Cependant je pensais que java est plus rapide que c sharp

  • @viewererdos
    @viewererdos Год назад +12

    There is nothing better than C/C++.

    • @Wwinstar
      @Wwinstar Год назад +9

      Assembly :)

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

      @@Wwinstar These C languages are “high-level” assembly languages.

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

      ​@@Wwinstar binar code)))))

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

      @@Wwinstar still not better?

    • @doublekamui
      @doublekamui Год назад +2

      maybe rust, it's design is good too for avoid memory leak when programmer forget to delete variable or other human error, and zig but this is too new so less library.

  • @dan-tv1kp
    @dan-tv1kp Год назад +1

    Shoulda used GraalVM

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

    C++ is HUGE!

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

    and repeat the same, but with 10000+ online users, interacting with the system, please

  • @jamestk656
    @jamestk656 9 месяцев назад

    For the applications I make, language execution speed pales in comparison to database access over a network lol. If anything, I'd be much more interested in memory consumption of each since that's usually the constraint I run into the most.

    • @Anubis1101
      @Anubis1101 9 месяцев назад

      thats why there are so many different languages, and the argument over whats best is ever ongoing.
      you dont know for sure whats best for you until you test it yourself.

  • @gizlischone2289
    @gizlischone2289 8 месяцев назад

    it means python isn't a turtle

  • @jorge.barcelos
    @jorge.barcelos 11 месяцев назад

    Python has no JIT bro

  • @phononmaser1024
    @phononmaser1024 Год назад +2

    JavaはJVMの起動にも時間がかかるからこう言う様なちょっとしたコードを実行するには部が悪すぎる

  • @aniketbisht2823
    @aniketbisht2823 11 месяцев назад +2

    Java, slow to compile and slow to run. The fuck do you get. But there are these Java people out there brainwashed about how good their JVM/JIT is, "once JIT kicks in, then ....".
    If you care about performance, you don't rely on some mystical tooling, you check and analyse the assembly that has been generated and make best use of the low level primitives, that the hardware and the operating system exposes, for your specific use case and of course you measure the performance.
    With Java you get minimal control over these low level details and need to rely on the almighty JVM.

    • @MikeM-ps1kn
      @MikeM-ps1kn 8 месяцев назад

      You don't seem to get the point. The level of optimization you're talking about is not feasible in most cases. Just run the examples yourself and get your facts straight. I've slightly modified this video's example: The array of numbers to be sorted is 5000 and in every language 1000 iterations are done, the lowest time is used to compare performance. Result: C++ ( g++ -Ofast -O3 -march=native) uses double the time as the OpenJDK 17 build, python is 100x slower, even. Try to optimize that with pure C++, in the end you'll resort to C with inline assembly to beat the JIT compiler's output. And then you've just optimized for one platform.

    • @Bob-1802
      @Bob-1802 5 месяцев назад

      If Java is slow to compile, Kotlin (based in Java) compile time is horrendously slow. Almost an order of magnitude slower 🥱😴

  • @tzimisce1753
    @tzimisce1753 8 месяцев назад

    1 second = 1000000000 nanoseconds.
    Python has PyPy now, which is incredibly fast, but the only drawback is that it can't support every module/library because it doesn't support C properly.
    PyPy used to have the drawback of not having support for the data science modules, but it does now in 2024.
    And Cython can be used to make Python faster than C++.

    • @yancgc5098
      @yancgc5098 6 месяцев назад +1

      Cython is not faster than C++ bruh 😂

    • @tzimisce1753
      @tzimisce1753 6 месяцев назад

      @@yancgc5098 Measure it yourself if you don't believe me.

  • @Fillrate
    @Fillrate 9 месяцев назад

    I tried it myself and found that C++ resulted in being twice as slow as Java😅

    • @kenarnarayaka
      @kenarnarayaka 8 месяцев назад +1

      how tf is that even possible.

  • @DavidKujo
    @DavidKujo 8 месяцев назад

    The problem for most Python programmers is that they don't know how the language works. Your test is simply wrong.

    • @JoseLucasd
      @JoseLucasd 6 месяцев назад

      Lol yes. Having no low level understanding really is a problem (this isnt for the video).

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

    ....

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

    com

  • @duvaljoannaprisca7856
    @duvaljoannaprisca7856 10 месяцев назад

    😂🎉😢😢

  • @duvaljoannaprisca7856
    @duvaljoannaprisca7856 10 месяцев назад

    😂🎉😢😢