Python vs C++ vs Java (Speed Comparison)

Поделиться
HTML-код
  • Опубликовано: 25 авг 2024
  • this is a speed test between java, c++ and python. the code might not be perfect so please let suggest any improvements in the comments.
    All the code used in one .txt file:
    drive.google.c...

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

  • @petemartinez3017
    @petemartinez3017 10 месяцев назад +121

    Python is good for scripting and readability but not performance.

    • @gostan2718
      @gostan2718 10 месяцев назад +25

      I find it hard to read Python

    • @I_am_Raziel
      @I_am_Raziel 9 месяцев назад +4

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

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

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

    • @I_am_Raziel
      @I_am_Raziel 8 месяцев назад +4

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

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

      ​@@I_am_Razielespecially the bunch of compiled libs like numpy

  • @BlueIsLeet
    @BlueIsLeet 6 месяцев назад +45

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

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

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

  • @Chris-ty7fw
    @Chris-ty7fw 9 месяцев назад +42

    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 8 месяцев назад +1

      Correct

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

      that makes a lot of sense, thanks for the info

    • @aniketbisht2823
      @aniketbisht2823 7 месяцев назад +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 7 месяцев назад +1

      ​@@aniketbisht2823 Read the original comment again

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

      @@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 10 месяцев назад +21

    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 месяцев назад +7

      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 6 месяцев назад +1

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

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

      C is the fastest

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

      @@bradleywang289 Assembly is theoretically faster than C

  • @user-xc1rl4nc4q
    @user-xc1rl4nc4q 11 месяцев назад +56

    Try in cases where you put big arrays like 1million with big amount of cicles like 10k i then you will see that java is fast as c lang, i did test already, using mergeSort algorithm

    • @NikGlt
      @NikGlt 10 месяцев назад +3

      Idk why but after learning data structures, feels like merge sort algorithm is the most weird and for some reason uncomfortable to write (by write I mean you are given a few image examples of how the sort works but you need to think of the code yourself, radix is child's play for me in comparison to merge sort)

    • @User-je7gf
      @User-je7gf 9 месяцев назад +7

      The reason why java is so slow here is because it has to initialize the JVM (Java virtual machine) only then can it start running the code
      Where as C++ can start running immediately

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

    Compare it with C# 11

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

    Super music and comparison

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

    @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++

  • @Swyateg
    @Swyateg 10 месяцев назад +16

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

    • @oktay9784
      @oktay9784 10 месяцев назад +18

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

    • @hba6018
      @hba6018 10 месяцев назад +4

      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 10 месяцев назад

      @@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 10 месяцев назад

      @@goblinjedly9528 keep calm bro Im just joking

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

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

  • @dragonbleu1205
    @dragonbleu1205 13 дней назад

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

  • @Timely-ud4rm
    @Timely-ud4rm 6 месяцев назад +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 6 месяцев назад

      Rust

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

      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

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

    hey atleast c++ was consistent

  • @DinHamburg
    @DinHamburg 9 месяцев назад +1

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

  • @user-kz5jm8tn3w
    @user-kz5jm8tn3w 20 дней назад

    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.

  • @Pyovali
    @Pyovali 10 месяцев назад +8

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

    • @getforfree8344
      @getforfree8344 9 месяцев назад +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 9 месяцев назад

      ah yes the low level language C@@getforfree8344

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

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

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

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

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

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

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

    Did you optimize the code According to language

  • @NewLondonMarshall
    @NewLondonMarshall 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

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

    JS - what is compilation ?

  • @viewererdos
    @viewererdos 9 месяцев назад +11

    There is nothing better than C/C++.

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

      Assembly :)

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

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

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

      ​@@geekygymrat binar code)))))

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

      @@geekygymrat still not better?

    • @doublekamui
      @doublekamui 8 месяцев назад +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.

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

    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.

  • @user-vh4mf4ux2m
    @user-vh4mf4ux2m 2 месяца назад

    What about c#?

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

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

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

    I like the music :P

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

    it means python isn't a turtle

  • @dan-tv1kp
    @dan-tv1kp 9 месяцев назад +1

    Shoulda used GraalVM

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

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

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

    C++ is HUGE!

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

    Python has no JIT bro

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

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

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

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

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

    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 6 месяцев назад

      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.

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

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

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

    com

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

    ....

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

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

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

      how tf is that even possible.

  • @aniketbisht2823
    @aniketbisht2823 7 месяцев назад +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 5 месяцев назад

      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 2 месяца назад

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

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

    😂🎉😢😢

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

    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 2 месяца назад +1

      Cython is not faster than C++ bruh 😂

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

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

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

    😂🎉😢😢