it's dam simple thing why it C type languages runs faster. => Don't want to harm anyone's feelings but originally Python was created for "Power users" i.e. people who wanna play around with things here and there. It was never meant to b full blown development language. Due to it's ease of use purpose people started use it everywhere. -> Python is Interpreted so when you run it compiles and execute the code. ->Python is tapeless/dynamic typed that means at runtime it will keep checking for which type of variable it is. => Being C/C++ system languages it has mammoth amount of optimization from Compilers and optimizers like LLVM toolchain. A experienced c/c++ dev can even make it run more faster by using specific compiler flags when compiling C/C++.
@@knowledgedose1956 Well theoratically it's typed but it just doesn't help to improve runtime performance. The interpreter keeps track of type but because type can change dynamically...it can't do much.
@@knowledgedose1956sure you can hint the interpreter that you will pass a certain type, but the interpreter still accepts other types. Thus, it is not typed at all. I've never studied it under the hood but I bet it uses some sort of void pointer and meta information accepting anything that comes from the user and using an algorithm to determine how to deal with the void pointer using the meta information.
@cristianoo2 it is typed. if an object doesn't have method, you won't be able to call it. yes, you probably will understand this later than needed, unless you use typechecking, but python has types. it is just not compiled language.
iirc, the reason you were getting 0s in C was because the OS sets memory to 0 for security reasons. for example if you close Chrome, you wouldn't want some other program to be able to read your bookmarks from memory.
That is correct. But, the garbage data could still happen say, when you've called a function, it pushes its elements on the stack, and then when it returns your local variables are pushed in the same overlapping region. Then, the 'dead' data from that function would still be reflected here.
@@comradepeter87 this pretty much and let's not forget the possibility of other programs not handling garbage collection of miss managing memory as that could also result in "oddities" anyways I've always said hope for the best but prepare for the worst and C seems to be pretty good at proving why it's important to prepare for things to go wrong as no matter how fool proof or secure an OS may claim to be there will always be another fun oopsie moment sooner or later.
I believe it is also categorized as undefined behavior, so the C standard doesn’t say what should happen if you use an uninitialized value, meaning it could be entirely up to the compiler or operating system.
On Linux systems, whenever you request a page of memory from the kernel, it is always zeroed out before you get it, unless your kernel was compiled with the CONFIG_MMAP_ALLOW_UNINITIALIZED option AND you specify MAP_UNINITIALIZED in the flags argument to mmap.
@samconnelly7630 That's a good point! I had actually forgotten about the whole different systems have different base standards aspect of things so if you give a C language example that works fine on Linux (and is valid in a standard use case scenario) it could be insecure or even unstable on another system if not properly adapted by the viewer which if I'm being honest I can't really imagine many people are going to consider such details aside from actual dedicated/career programmers that is.
6:36 No. Your code IS direcly running on the CPU (or GPU/NPU). It is running is Ring 3 mode - it has to call OS for allocating RAM, storage acsess, or talking to somewhere (other processes or network).
exactly. obviously your code has to run on CPU but it cannot bypass OS. ring 3 IS part of your operating system. kernel IS part of your operating system
@@codedamn ring 3 is the user-mode, has to do with what the CPU will allow the software to do. Doesn't have to do with the OS itself, all programs run on the CPU directly. What do you even mean by "it cannot bypass OS"? The OS can't execute programs, only the CPU can. The CPU cares for all the details, assigning Memory allocations, file access and even stopping/interrupting the program. So there is nothing to bypass, it's quite the opposite: The OS will start the program, which will then run directly on the CPU.
@@RustedCroaker Nope, these microbenchmarks are very flawed in general. The main thing that'd impact Java's performance in the real world isn't its ability to JIT such a simple hot-loop, it's the garbage collection and the large amount of memory pressure that Java applications exert on the host system.
@@RustedCroaker I agree that Jit is really great ( I myself use it ), but I will be honest, I have spent a lot of time on systems programming ( the code can be optimised a lot, like for example verterization, enabling agressive loop unrolling, passing release mode compiler flags, building for machine specific using compiler flags again ). I don't mean to say that java is bad, it's just that C is always going to faster ( assuming the person writing knows every inch of C ).
Okay but I am still gonna use Python. edit : Y'all boomers need to chill as if Python is the only language I know. I have used Java, C++ and JavaScript too. Language is just a syntax when you know the basic concepts.
Can I just say that looking at more and more Indian developers, I had gotten jaded at our industry as it was very rare where I found developers that would actually care about what's going underneath the layers of abstraction or know about it. As a consequence, there's so much knowledge gap that people are not aware of. BUT, after watching this channel and reading the comment section here, I'm glad to say that it's not all developers and some indian devs do actually care to go in depth and to all of you, I respect you. I wish I had more fellow devs like you I could chat to, it's topics like these that are actually fascinating and not what's the next framework.
Really enjoying the insights in this thread! It’s awesome to see so many like-minded people here. Hope we can keep the conversation going and exchange ideas!
It's a bit misleading to say that userland applications "don't run on the CPU". They DIRECTLY, NATIVELY run their machine code on the CPU. There is no translation happening on-the-fly or otherwise by the OS except at startup by the OS' loader which might resolve .so/DLL dependencies (yes, not even virtual address mapping). It's better to think of OS as a bunch of "dead"/inactive code that CPU is responsible for invoking/calling on specific triggers/interrupts. If OS actually actively participated in your code execution every cycle, nothing would ever get done.
Better to put it in this way, our user application just translates to op-codes and system calls when we need to access hardware/network etc. When we need to do something that is outside the scope of our program we raise an interrupt. Now OS handles all the interrupts and toggles the user/kernel mode flags in CPU if some restricted tasks needs to be performed. SO basically our program at interrupts just calls some code/function that is the part of the os and is handled directly by the OS and not the program. Obviously this is done to enhance security.
@@Chief_Avy I have a degree in Computer Science so I have studied about how OS and CPUs works in my college as well. All the best keep learning and growing 😊
The way you explained how operating system sits between your code and the CPU is misleading. Your code directly runs on the CPU, but it runs on user mode. The operating system manages the MMU so that the times when your program is scheduled, it is not allowed to access memory outside of the allocated region.
@codedamn true, but that simplification should be pointed out, because the video explanation makes it look like your program is running on a vm, not on the cpu directly.
@@AllMightGaming-AMG the program has to run on CPU at the end (where else would it run), even on a VM, underlying physical core is responsible for running your computer. to your statement, "user mode" and "kernel mode" are constructs defined by your OS. your physical CPU core does not know/care about permissions
@@codedamn Hey, the CPU does know about user mode and kernel mode, it is a bit set in the cpu itself. It is fine if you didn't know this but I'm surprised that you'd say this without doing your own research, it's just a search away.
@@codedamn it'd be impossible to write secure os where the user mode application is able to access anything without a hardware feature like a kernel mode flag. OS alone can't do this. A lot of microcontrollers are there without this feature, and you can't write an os with this kind of user mode application feature on them because of this reason.
python very friendly for observer (teacher or trainer or non professional coder) to read code. very expensive for real or production system, just like performance ratio from this video title, at least when on production, using c we only need 1 server, but using python we need 150 server for same output
Really enjoying the insights in this thread! It’s awesome to see so many like-minded people here. Hope we can keep the conversation going and exchange ideas!
Lot of the delay is due to the OS. Any round robin scheduler will only allow a slice of the CPU time (to create the illusion of servicing all other open tasks/application). This exacerbates the slow down for interpreted languages (Since a pre-compiled binary can be executed in the slice of time the OS provides to the app). Try running this on an embedded micro with an RT OS. I tried it on a Peta Linux running on a Xilinx SOC(ZCU 104) and the difference is not that bad. But I understand for people working on old Batch processing/ Round robin OS like windows this might be an issue.
JavaScript should be slow as Python or slower in this bucket. They go way way beyond JIT. V8 optimizes the living heck out of the code as well in deeeeep ways. I bet Python could have this too
You have to differentiate the use cases here. Python is usually used for running something like web framework where the bottle neck is I/o. And C is run for something like device drivers and encoder/decoders which run billions of loops the bottle neck is CPU itself. In simpler language you don't need to spend hours to write a C program to spend 0.001 seconds in execution and 100ms waiting for I/o. While you can spend minutes writing a python code that will execute in 0.1 ms and wait 100 ms for I/o. So both have their use cases.
All HLL have guardrails including Java and Javascript however they are not that slow. The main reason I guess python is being interpreted language. Javascript is also interpreted language however due to JIT compiler and v8 engines optimisation make it faster. Pypy is JIT for python which as very close performance to javascript as we can see in experiment. But for normal python environment since it’s completely being interpreted line by line it’s slow
Not really, most of the actual inference/ML libraries have actual core performant part written in C anyways. The performance impact would not be big enough.
JS/Bun, JS/Node, and JS/Deno - we are definitely going to see more JavaScript runtimes in the future. We might even see compiled JavaScript, offering a flavor similar to compiled languages. The syntax would remain the same, but the compiler would handle the code differently from how the V8 engine does. like a true compiled language.
It'd be very complex to create a truly compiled (AOT) JS version while still being 100% spec compliant. Immediately what stands out to me are functions like `exec()` that execute a JS string. An obvious shortcut would be spin up a JS compiler that, at runtime, compiles that JS string. But that string could have variables referencing the exact current state of your own program, so this compiler now needs to tap into your program state as well. Probably not impossible, but difficult enough to be impractical - especially because JS' JIT is very impressive anyways.
@VivekYadav-ds8oz it might be complicated. But it's not impossible. Js ecosystem is very large. And someone might be insane enough to start the project 😶
@@Takatou__Yogiri how would a weakly typed dynamic programming language such as Javascript be compiled AOT? The best we can get is JIT which is already there. Maybe we can do that for Typescript though
Python's slowness is especially interesting when you consider that it's not just an interpreted language. It is a VM similar to Java. The only real difference is that the bytecode is not precompiled to a file and run through the VM separately. That in itself can contribute to some of the slowdown, but still does not account for how slow it is at the end of the day. I might be talking out of my ass as I am not 100% sure at the time of writing this, but I would guess that it is does multiple passes during compilation to bytecode. This has a lot of advantages, but it is also significantly slower. That would again not fully explain it. Factoring in what I've mentioned, it should at least be up there with JS or even Kotlin. There is definitely a lot more to the story as this test is not the only one where you can see such a significant difference in speed between Python and even other scripting languages/VMs.
I guess in C int variables has 0 as the default value (not a garbage value) so it also has some guardrails but yeah it’s possible that assembly instruction for C might be less compare to other languages and most of complied languages can opt in to have less guardrails as they already do a lot of checks prior to conversion and awesome video as always.
I don't think that "0" part is because of C as it doesn't offer any such guarantees. It's just the OS clearing any memory to 0 before giving it to the userland application. You can verify this by first calling a function that allocates a ton of stack variables with arbitrary values and then returns out. Then, in the main function, you allocate some uninitialised integers on the stack and print their values. I bet this time they would have non-zero values.
this is a very incorrect comparison, maybe the code does the same thing, but the implementation is bad: 1. c/c++ is first compiled and then executed, while py/js is executed as it is implemented. 2. Python uses methods: range and random, which greatly slows down the program, especially randint
@@Aditya-p4t yes, its just a language there are many gpu accelerated workloads like cuDF , cuPy, Dask-cuDF, PyTorch and TensorFlow (with GPU acceleration) etc. that is why python is preferred in data science (however bend programming language can be significantly faster as it is based on C)
So isn't python better than cpp if it is making sure that everything is correct at runtime as we can detect error early?And i only use cpp for dsa so i dont know much in details but i heard neetcode say that cpp is much much more than what we use regularly for dsa ,is it this stuff he was talking about like in big companies the developer define everything by themselves but for language like js it is pre defined ( i dont know much about python)
Language scope for C++ is incredibly insane. I stopped moments after learning about "concepts" (an actual term, basically similar to traits in Rust) when I saw what's more to come. Learning about STL and templating would get you far enough, but learning the entire language is incredibly difficult. I'd wager to say there's less than 10 people in the whole world that understand all the ins-and-outs of C++ in every edge case.
@@comradepeter87 Yeah. I knew C inside and out to the minute details so I thought I'd do the same with C++. Nope. Never. And that was 20 years ago, now the language is an order of magnitude more complex. Yes, you can comfortably use it without knowing it all but I would prefer to understand it all.
I feel pity for those who compares languages based on their execution speed.Every language has it's own pros and cons, they will not talk about how fast the development becomes while using python but all they want is to ask their c++/rust doubts using pyhton built LLMs
Those python built LLMs have AI libraries written in low level languages like C. All the matrix operations and stuff are handled by the C code. Python only makes the necessary function call. The reason you can do fast development in python is bcz of having vast majority of libraries that already does most of your job. You're right about the rest.
@@husreihn1070 i don't think so i have used both and their architecture is almost similar with jit and vms. So i don't think their will br any difference.
Yes python is really slow! Thats why libs like Pandas are written in C under the hood. Sometimes i is a tool. It makes you develop things faster than any language. I love it.
No you are mistaken. Every request from your user creates an iteration even packages you use have some kind of looping and iterations going on. Yes you can easily hit a billion iteration in prod.
@@Chat_De_Ratatoing I recently learned that most modern compilers (including LLVM) just generate machine code directly from their IR. So, it's actually the opposite. Compilation converts code to binary. You can add the compilation to assembly by adding -S like this: gcc file.c -S -o file.S
C/C++ compilation are multiple steps including ASM. There are 5 to 6 steps in total including compiling, optimization, assembler and linking. These all happen at compile time however and so don't affect execution speed whatsoever. The actual program execution is done on pure binary machine code (.bin or .exe) wich is one of the main reasons i think behind the blazing speed of languages like C/C++ and Rust. These many steps are however why languages like C and C++ in contrast to the fast execution speed instead takes forever to compile. This is seen clearly when using game engines like Unity and Unreal Engine. Higher level languages like Unity C# and Unreal Blueprint have fewer compile steps but more execution steps so they compile much faster but execute slower because they don't compile right down to machine code so extra steps are needed then during the execution. In contrast Unreal C++ is blazing fast to run but it takes between 10 - 20 minutes each time to compile. Also however C++ is an old language and I heard somwhere that much of the long compile time is because the compiler reads each file like 100000000000000 times during compilation to see if anything has changed. More modern low level languages like Rust don't do that and so compile faster.
@@johnpekkala6941 You are, I think, right on the money why C++ takes forever to compile. The language semantics pretty much force the compiler to read and parse and stuff the same files over and over again. This is the main reason I abandoned C++ years ago. The insane compile times. Plus the way people avoid using name spaces and spell out everything std::xxx::yyy instead of writing code that concentrates on the actual thing being done. And the corner cases of the language do not help either.
simple answer , because of GIL Lock , that will not let you use full power of multiprocessing. Also , C is closer to processor commands , that no one else , except assembly.
Very interesting to see bun being equal-ish to golang in these loops and kotlin beating golang. I guess the point of golang is simplicity. which I appreciate. I would've liked a lua benchmark
Its really surprising to see go having similar speeds to JS/Bun... And the fact that Java/Kotlin beating them is even more astounding I guess I have the wrong notion regarding golang, thinking that it will slightly slower speeds than Rust
@@AyushVachhani the most syntax volume and memory allocation/GC possible per iteration. I don't know if python will progressively optimize like the modern JS engine do or keep interpreting and I wonder about the hard limits of its GC. I'm not saying that the language is wrong, I know it's used in performance context like in AI but because it's barely scripting/orchestrating native binaries doing the heavy lifting. In the optics of testing the language, I don't know if we can use the best use case if their point is to rely on native binaries. The equivalent for JS would be to test it using c code compiled in WASM, it wouldn't make sense as a valid JS entry.
What's the point of running a simple loop and benchmark 😂... In real world you will never be writting simple loop only.. if this was the only job of a language then all these languages wouldn't have been invented.. each language has it's own usecases, solves difference types of problems, One language would be enough in that case.😊
I don't know who fed this to you, but JS is surprisingly fast - miles ahead of Python. V8 is an incredible piece of engineering and I recommend more people to read/watch content on it. Just check how V8 handles strings (it's not a simple vector of bytes).
All this python is slow talk is bullshit. Programming languages are tools made to do different things efficiently . You want to write something to be very fast and resource efficient go with c, c++ or rust . You want to make a backend of a website quickly go for python , php or something else . These tools are there for us to choose and use them according to our requirement. If we are writing the backend of a site in c and site has 2 visitors per day then we are just wasting our time
why not this is just one aspect. When we say some language x is faster than language y, it doesn't necessary means that all the things will be 100% faster in x than y. Some things could be faster in y even though generally it is slower language in average compare to x.
it's dam simple thing why it C type languages runs faster.
=> Don't want to harm anyone's feelings but originally Python was created for "Power users" i.e. people who wanna play around with things here and there. It was never meant to b full blown development language. Due to it's ease of use purpose people started use it everywhere.
-> Python is Interpreted so when you run it compiles and execute the code.
->Python is tapeless/dynamic typed that means at runtime it will keep checking for which type of variable it is.
=> Being C/C++ system languages it has mammoth amount of optimization from Compilers and optimizers like LLVM toolchain. A experienced c/c++ dev can even make it run more faster by using specific compiler flags when compiling C/C++.
python is not typeless, it is strictly typed and dynamic typed language.
@@knowledgedose1956 Well theoratically it's typed but it just doesn't help to improve runtime performance. The interpreter keeps track of type but because type can change dynamically...it can't do much.
@@knowledgedose1956wrong. Python is typeless. You can declare a var, put an int on it then put a string on it and the language will accept that.
@@knowledgedose1956sure you can hint the interpreter that you will pass a certain type, but the interpreter still accepts other types. Thus, it is not typed at all.
I've never studied it under the hood but I bet it uses some sort of void pointer and meta information accepting anything that comes from the user and using an algorithm to determine how to deal with the void pointer using the meta information.
@cristianoo2 it is typed. if an object doesn't have method, you won't be able to call it. yes, you probably will understand this later than needed, unless you use typechecking, but python has types. it is just not compiled language.
iirc, the reason you were getting 0s in C was because the OS sets memory to 0 for security reasons. for example if you close Chrome, you wouldn't want some other program to be able to read your bookmarks from memory.
That is correct. But, the garbage data could still happen say, when you've called a function, it pushes its elements on the stack, and then when it returns your local variables are pushed in the same overlapping region. Then, the 'dead' data from that function would still be reflected here.
@@comradepeter87 this pretty much and let's not forget the possibility of other programs not handling garbage collection of miss managing memory as that could also result in "oddities" anyways I've always said hope for the best but prepare for the worst and C seems to be pretty good at proving why it's important to prepare for things to go wrong as no matter how fool proof or secure an OS may claim to be there will always be another fun oopsie moment sooner or later.
I believe it is also categorized as undefined behavior, so the C standard doesn’t say what should happen if you use an uninitialized value, meaning it could be entirely up to the compiler or operating system.
On Linux systems, whenever you request a page of memory from the kernel, it is always zeroed out before you get it, unless your kernel was compiled with the CONFIG_MMAP_ALLOW_UNINITIALIZED option AND you specify MAP_UNINITIALIZED in the flags argument to mmap.
@samconnelly7630 That's a good point! I had actually forgotten about the whole different systems have different base standards aspect of things so if you give a C language example that works fine on Linux (and is valid in a standard use case scenario) it could be insecure or even unstable on another system if not properly adapted by the viewer which if I'm being honest I can't really imagine many people are going to consider such details aside from actual dedicated/career programmers that is.
In python 3.13 they introduced JIT within the language and performance for cpu Bound task will increase in future version of python.
6:36 No. Your code IS direcly running on the CPU (or GPU/NPU). It is running is Ring 3 mode - it has to call OS for allocating RAM, storage acsess, or talking to somewhere (other processes or network).
exactly. obviously your code has to run on CPU but it cannot bypass OS. ring 3 IS part of your operating system. kernel IS part of your operating system
@codedamn and there is a mistake in the video saying "code doesnt run direcly on the CPU" when it clearly does. Mistake at 6:36.
@@codedamn ring 3 is the user-mode, has to do with what the CPU will allow the software to do. Doesn't have to do with the OS itself, all programs run on the CPU directly. What do you even mean by "it cannot bypass OS"? The OS can't execute programs, only the CPU can. The CPU cares for all the details, assigning Memory allocations, file access and even stopping/interrupting the program. So there is nothing to bypass, it's quite the opposite: The OS will start the program, which will then run directly on the CPU.
The most satisfying thing in the test is the fact Java perform almost as good as C and Rust.
Then the tests are flawed lop
@@AyushVachhani No, that means modern Java JIT is technological marvel that can beat any AOT with ease
@@RustedCroaker Nope, these microbenchmarks are very flawed in general. The main thing that'd impact Java's performance in the real world isn't its ability to JIT such a simple hot-loop, it's the garbage collection and the large amount of memory pressure that Java applications exert on the host system.
@@RustedCroaker I agree that Jit is really great ( I myself use it ), but I will be honest, I have spent a lot of time on systems programming ( the code can be optimised a lot, like for example verterization, enabling agressive loop unrolling, passing release mode compiler flags, building for machine specific using compiler flags again ).
I don't mean to say that java is bad, it's just that C is always going to faster ( assuming the person writing knows every inch of C ).
@@RustedCroaker Also trust me, the optimized version could run a lot faster than java ( no hate to java again )
There is PR in repo which enables JIT for PHP and it gains some ground by reducing till 2.6s instead of 9.9s shown.
Yea that is nice. I also have php jit enabled.
Okay but I am still gonna use Python.
edit : Y'all boomers need to chill as if Python is the only language I know. I have used Java, C++ and JavaScript too. Language is just a syntax when you know the basic concepts.
😂 me too
We are even using it because of it’s simplicity 😢😂
I choose it all day 😂
As long as you aren’t writing a program that requires a billion nested loop iterations.
I wished he would have tested mojo too.
Can I just say that looking at more and more Indian developers, I had gotten jaded at our industry as it was very rare where I found developers that would actually care about what's going underneath the layers of abstraction or know about it. As a consequence, there's so much knowledge gap that people are not aware of.
BUT, after watching this channel and reading the comment section here, I'm glad to say that it's not all developers and some indian devs do actually care to go in depth and to all of you, I respect you. I wish I had more fellow devs like you I could chat to, it's topics like these that are actually fascinating and not what's the next framework.
Really enjoying the insights in this thread! It’s awesome to see so many like-minded people here. Hope we can keep the conversation going and exchange ideas!
this kind of lazy devs ai will replace first
a lot of libraries for python are implemented in other languages though, like Rust, so the user code will be slow, but not always the library code.
It's a bit misleading to say that userland applications "don't run on the CPU". They DIRECTLY, NATIVELY run their machine code on the CPU. There is no translation happening on-the-fly or otherwise by the OS except at startup by the OS' loader which might resolve .so/DLL dependencies (yes, not even virtual address mapping). It's better to think of OS as a bunch of "dead"/inactive code that CPU is responsible for invoking/calling on specific triggers/interrupts. If OS actually actively participated in your code execution every cycle, nothing would ever get done.
Better to put it in this way, our user application just translates to op-codes and system calls when we need to access hardware/network etc.
When we need to do something that is outside the scope of our program we raise an interrupt. Now OS handles all the interrupts and toggles the user/kernel mode flags in CPU if some restricted tasks needs to be performed.
SO basically our program at interrupts just calls some code/function that is the part of the os and is handled directly by the OS and not the program. Obviously this is done to enhance security.
@@KeshariPiyush24 Hi i found your know remarkable can u kind of guide me how can i study/ gain exposure to this kind of knowledge .
@@Chief_Avy I have a degree in Computer Science so I have studied about how OS and CPUs works in my college as well. All the best keep learning and growing 😊
The way you explained how operating system sits between your code and the CPU is misleading. Your code directly runs on the CPU, but it runs on user mode. The operating system manages the MMU so that the times when your program is scheduled, it is not allowed to access memory outside of the allocated region.
It’s a simplified explanation and just to invoke curiosity. I can cover everything in depth and it will become a 2 hour video
@codedamn true, but that simplification should be pointed out, because the video explanation makes it look like your program is running on a vm, not on the cpu directly.
@@AllMightGaming-AMG the program has to run on CPU at the end (where else would it run), even on a VM, underlying physical core is responsible for running your computer. to your statement, "user mode" and "kernel mode" are constructs defined by your OS. your physical CPU core does not know/care about permissions
@@codedamn Hey, the CPU does know about user mode and kernel mode, it is a bit set in the cpu itself. It is fine if you didn't know this but I'm surprised that you'd say this without doing your own research, it's just a search away.
@@codedamn it'd be impossible to write secure os where the user mode application is able to access anything without a hardware feature like a kernel mode flag. OS alone can't do this. A lot of microcontrollers are there without this feature, and you can't write an os with this kind of user mode application feature on them because of this reason.
python very friendly for observer (teacher or trainer or non professional coder) to read code.
very expensive for real or production system, just like performance ratio from this video title, at least when on production, using c we only need 1 server, but using python we need 150 server for same output
Really enjoying the insights in this thread! It’s awesome to see so many like-minded people here. Hope we can keep the conversation going and exchange ideas!
Lot of the delay is due to the OS. Any round robin scheduler will only allow a slice of the CPU time (to create the illusion of servicing all other open tasks/application). This exacerbates the slow down for interpreted languages (Since a pre-compiled binary can be executed in the slice of time the OS provides to the app). Try running this on an embedded micro with an RT OS. I tried it on a Peta Linux running on a Xilinx SOC(ZCU 104) and the difference is not that bad. But I understand for people working on old Batch processing/ Round robin OS like windows this might be an issue.
Only Native Codes (Rust , C , C++) Compiled into Assembly then binary. Vm languages Uses Jit , Aot or Normal Iteration.
JavaScript should be slow as Python or slower in this bucket. They go way way beyond JIT. V8 optimizes the living heck out of the code as well in deeeeep ways. I bet Python could have this too
This is what I've been telling everyone, yes python is faster to throw a program together, BUT it's very unoptimized in comparison to C/C++
u can increase python speed using PYPY
@Aditya-p4t you shouldn't need to install additional modules to make a coding language faster that has inherent issues running fast
You have to differentiate the use cases here. Python is usually used for running something like web framework where the bottle neck is I/o.
And C is run for something like device drivers and encoder/decoders which run billions of loops the bottle neck is CPU itself.
In simpler language you don't need to spend hours to write a C program to spend 0.001 seconds in execution and 100ms waiting for I/o. While you can spend minutes writing a python code that will execute in 0.1 ms and wait 100 ms for I/o.
So both have their use cases.
The fact PyPy is 3x slower than C and Python is 150x speaks volumes about Python despite everything you explained wouldn't you say?
All HLL have guardrails including Java and Javascript however they are not that slow.
The main reason I guess python is being interpreted language. Javascript is also interpreted language however due to JIT compiler and v8 engines optimisation make it faster. Pypy is JIT for python which as very close performance to javascript as we can see in experiment. But for normal python environment since it’s completely being interpreted line by line it’s slow
Where is assembly?
I have seen that graphic before, and i thought it was some fallacy, as i myself had done similar comparisons in past.
Your explanation makes sense.
Getting addicted to this channel
So I'm maglu(jo jaadu na jane) in this language and all
That means stable diffusion was written in c language rather than python it could be faster?
No
@Mayank-lf2ym ok
@@Watch-Kiran yes
Not really, most of the actual inference/ML libraries have actual core performant part written in C anyways. The performance impact would not be big enough.
@@comradepeter87 thank you
JS/Bun, JS/Node, and JS/Deno - we are definitely going to see more JavaScript runtimes in the future. We might even see compiled JavaScript, offering a flavor similar to compiled languages. The syntax would remain the same, but the compiler would handle the code differently from how the V8 engine does. like a true compiled language.
It'd be very complex to create a truly compiled (AOT) JS version while still being 100% spec compliant. Immediately what stands out to me are functions like `exec()` that execute a JS string. An obvious shortcut would be spin up a JS compiler that, at runtime, compiles that JS string. But that string could have variables referencing the exact current state of your own program, so this compiler now needs to tap into your program state as well. Probably not impossible, but difficult enough to be impractical - especially because JS' JIT is very impressive anyways.
@VivekYadav-ds8oz it might be complicated. But it's not impossible. Js ecosystem is very large. And someone might be insane enough to start the project 😶
@@Takatou__Yogiri how would a weakly typed dynamic programming language such as Javascript be compiled AOT? The best we can get is JIT which is already there. Maybe we can do that for Typescript though
Python's slowness is especially interesting when you consider that it's not just an interpreted language. It is a VM similar to Java. The only real difference is that the bytecode is not precompiled to a file and run through the VM separately. That in itself can contribute to some of the slowdown, but still does not account for how slow it is at the end of the day.
I might be talking out of my ass as I am not 100% sure at the time of writing this, but I would guess that it is does multiple passes during compilation to bytecode. This has a lot of advantages, but it is also significantly slower. That would again not fully explain it. Factoring in what I've mentioned, it should at least be up there with JS or even Kotlin.
There is definitely a lot more to the story as this test is not the only one where you can see such a significant difference in speed between Python and even other scripting languages/VMs.
3:29 what software you using to write and draw in this video, please tell me
Except syscalls, native code runs directly on CPU
memory access are handled from the OS
I guess in C int variables has 0 as the default value (not a garbage value) so it also has some guardrails but yeah it’s possible that assembly instruction for C might be less compare to other languages and most of complied languages can opt in to have less guardrails as they already do a lot of checks prior to conversion and awesome video as always.
Default is garbage, not 0
I don't think that "0" part is because of C as it doesn't offer any such guarantees. It's just the OS clearing any memory to 0 before giving it to the userland application. You can verify this by first calling a function that allocates a ton of stack variables with arbitrary values and then returns out. Then, in the main function, you allocate some uninitialised integers on the stack and print their values. I bet this time they would have non-zero values.
this is a very incorrect comparison, maybe the code does the same thing, but the implementation is bad:
1. c/c++ is first compiled and then executed, while py/js is executed as it is implemented.
2. Python uses methods: range and random, which greatly slows down the program, especially randint
Additional 4 chars places Dart near C.
If that is the case would it be faster if using ai to convert all the python to c be something can be done to "optimise" a software back script?
where is c#?
Very intrigued by "static hermes" and how much it would speed up JS code.
At the end of this video "I'll see you in the next video very soon"😂 that is tomorrow daily one video 🔥🎉
we are doing course of data science and our instructor just told that R language is slower than Python however we see a difference here
u can increase python speed
@@Aditya-p4t yes, its just a language there are many gpu accelerated workloads like cuDF , cuPy, Dask-cuDF, PyTorch and TensorFlow (with GPU acceleration) etc. that is why python is preferred in data science (however bend programming language can be significantly faster as it is based on C)
The fact JS is that high up there is a modern miracle. Google really went hard with v8 way back when now 😮
Java is crazy speed for a managed code platform
Dynamic Types dont slow the language as much as u think
IntrEsting.. Mehul Bhai... Entrusting is something else
Wow Java being only 8% slower that rust and c in this case is what surprised me the most here
Python best for using. Not for production.
i maybe wrong but we can increase the python speed
OpenAI uses FastAPI for their ChatGPT Backend
Good one. Please also create an in depth video that explains everything from code to compiler etc then assembly , op code OS , CPU etc.
Most people won’t be interested in watching that
@@codedamn may be you can create part 1 and see the response. but it will be worth it as such contents are rare
There is llvm step and it will optimise lots of things
So isn't python better than cpp if it is making sure that everything is correct at runtime as we can detect error early?And i only use cpp for dsa so i dont know much in details but i heard neetcode say that cpp is much much more than what we use regularly for dsa ,is it this stuff he was talking about like in big companies the developer define everything by themselves but for language like js it is pre defined ( i dont know much about python)
Cpp is low level, and the cpp used to software development is completely different from the one you use in DSA
Language scope for C++ is incredibly insane. I stopped moments after learning about "concepts" (an actual term, basically similar to traits in Rust) when I saw what's more to come. Learning about STL and templating would get you far enough, but learning the entire language is incredibly difficult. I'd wager to say there's less than 10 people in the whole world that understand all the ins-and-outs of C++ in every edge case.
@@comradepeter87 Yeah. I knew C inside and out to the minute details so I thought I'd do the same with C++. Nope. Never. And that was 20 years ago, now the language is an order of magnitude more complex. Yes, you can comfortably use it without knowing it all but I would prefer to understand it all.
@@AyushVachhani I think it is totally wrong to call C++ low lever, on the contrary.
@@Axel_Andersen I am talking relative to Java. Else even C is high level, only binary and assembly would be lower level.
Don't blame it 😢 like this, it's definitely gonna improve in future
With jit it will improve. Both php and python.
thats why you dont use python in production but use mojo or something else.
What about c#
How can be Java way faster than Go?
Java ftw.
You get a built in gc. Nice syntaxes, easy to understand beautiful language and still fast af
I feel pity for those who compares languages based on their execution speed.Every language has it's own pros and cons, they will not talk about how fast the development becomes while using python but all they want is to ask their c++/rust doubts using pyhton built LLMs
Those python built LLMs have AI libraries written in low level languages like C. All the matrix operations and stuff are handled by the C code. Python only makes the necessary function call. The reason you can do fast development in python is bcz of having vast majority of libraries that already does most of your job. You're right about the rest.
Python is most loveable but code in whatever works for you and enjoy ❤
Where is swift
Seems like it must be a very specific pitfall. Why would most of the ai packages use python if it's so slow?
node is just c++
the sooner you understand that the better
Where is Swift?
I guarantee you that nothing running on the JVM is that close to native speed. Every time I have compared the JVM to Go or Rust it loses.
Disappointed to see no C#
c# is faster then java tho
@@husreihn1070 i don't think so i have used both and their architecture is almost similar with jit and vms. So i don't think their will br any difference.
@@husreihn1070 It's a bit slower actually. Similar to Kotlin.
@@imakhlaqXDyou're so uneducated for the topic, and writing comment blindly
I think it will be similar to Java if not better
Where is Zig
wheres asm?
Then why is python defacto for machine learning? Noob here
150x is magnitudes fastest than it was a few years ago
Bro, rather than the subject, I love and admire the way you speak English fluently and clearly, I just enjoy that.....
Yes python is really slow! Thats why libs like Pandas are written in C under the hood. Sometimes i is a tool. It makes you develop things faster than any language. I love it.
C# is better than all the shit langs showed in video 🎉
Python is probably the fastest at adding value.
I'm very sure I won't be conventinally running a billion iteration in production
No you are mistaken. Every request from your user creates an iteration even packages you use have some kind of looping and iterations going on. Yes you can easily hit a billion iteration in prod.
@hardtech1010 like I said, I won't be running a billion iteration conventinally, if the server or any package installed cares do it that's it's own.
Those extra 74 seconds you have spend writing the code in C😂
Eh, it makes up for the slower speed with faster development time
Java faster than go?? Suprising, even quarkus is a slower microservice framework than builtin golang, not even talking about spring
C# is missing :(
Nobody likes Microsoft
@RustedCroaker Sad. But is it true?
There are lots of enhancements improvementa in Microsoft World.
i tested it the performance is just below go at 0.78s
@@smtkumar007 you can send a pull request to that github repo
.net ?
I dont even code in C# but was also curious where it would place here
Its gonna be same level as java they have mostly similar architecture with jit and vms.
@@imakhlaqXD native aot
@@imakhlaqXDnop you're still on past
Dont see Julia there
Homo Sapiens is 100 times slower than Cheetah
The code does not get converted to ASM . Assembly is a separate language itself.
compilation converts code to ASM to a binary. You can avoid the compile to a binary step adding -S like this:
gcc file.c -S -o file.S
@@Chat_De_Ratatoing I recently learned that most modern compilers (including LLVM) just generate machine code directly from their IR. So, it's actually the opposite.
Compilation converts code to binary. You can add the compilation to assembly by adding -S like this:
gcc file.c -S -o file.S
C/C++ compilation are multiple steps including ASM. There are 5 to 6 steps in total including compiling, optimization, assembler and linking. These all happen at compile time however and so don't affect execution speed whatsoever. The actual program execution is done on pure binary machine code (.bin or .exe) wich is one of the main reasons i think behind the blazing speed of languages like C/C++ and Rust. These many steps are however why languages like C and C++ in contrast to the fast execution speed instead takes forever to compile. This is seen clearly when using game engines like Unity and Unreal Engine. Higher level languages like Unity C# and Unreal Blueprint have fewer compile steps but more execution steps so they compile much faster but execute slower because they don't compile right down to machine code so extra steps are needed then during the execution. In contrast Unreal C++ is blazing fast to run but it takes between 10 - 20 minutes each time to compile. Also however C++ is an old language and I heard somwhere that much of the long compile time is because the compiler reads each file like 100000000000000 times during compilation to see if anything has changed. More modern low level languages like Rust don't do that and so compile faster.
@@johnpekkala6941 You are, I think, right on the money why C++ takes forever to compile. The language semantics pretty much force the compiler to read and parse and stuff the same files over and over again. This is the main reason I abandoned C++ years ago. The insane compile times. Plus the way people avoid using name spaces and spell out everything std::xxx::yyy instead of writing code that concentrates on the actual thing being done. And the corner cases of the language do not help either.
Yes it does.
Don't worry gophers they didn't use go routine
Put pascal on the test too
No way Java is that much faster than Go
Ruby is faster than python?😢
I'm still flabbergasted that Python is used for data science / machine learning 😂
Only as the wrapper. Most of the framework is written in C
simple answer , because of GIL Lock , that will not let you use full power of multiprocessing. Also , C is closer to processor commands , that no one else , except assembly.
Python is developed for easy programming not speed.
Python is for shell scripts. Its easily to write shell scripts in python than real shell scripts. Period stop using it for backend and stuffs
Very interesting to see bun being equal-ish to golang in these loops and kotlin beating golang.
I guess the point of golang is simplicity. which I appreciate.
I would've liked a lua benchmark
Its really surprising to see go having similar speeds to JS/Bun...
And the fact that Java/Kotlin beating them is even more astounding
I guess I have the wrong notion regarding golang, thinking that it will slightly slower speeds than Rust
@@kevinnadar6077 but go is still good in low memory environment
Wtf no c#
I thought Python was overall thousands of times slower than C
What world do you live in 😂
@@AyushVachhani in some use case it's true, just that the test you are referring to isn't the worst case.
@@raph151515 lol, then what's the worse case, am genuinely interested to know
@@AyushVachhani the most syntax volume and memory allocation/GC possible per iteration. I don't know if python will progressively optimize like the modern JS engine do or keep interpreting and I wonder about the hard limits of its GC. I'm not saying that the language is wrong, I know it's used in performance context like in AI but because it's barely scripting/orchestrating native binaries doing the heavy lifting. In the optics of testing the language, I don't know if we can use the best use case if their point is to rely on native binaries. The equivalent for JS would be to test it using c code compiled in WASM, it wouldn't make sense as a valid JS entry.
replace t with d to sound indian
JVM faster than Go doesn't make sense
ok. who cares? Its only the 5020503205th video talking about speed of languages.
What's the point of running a simple loop and benchmark 😂... In real world you will never be writting simple loop only.. if this was the only job of a language then all these languages wouldn't have been invented.. each language has it's own usecases, solves difference types of problems,
One language would be enough in that case.😊
Bruh js being faster than python lmao 💀💀💀
Js is always faster than python. Python is a shit
I don't know who fed this to you, but JS is surprisingly fast - miles ahead of Python. V8 is an incredible piece of engineering and I recommend more people to read/watch content on it. Just check how V8 handles strings (it's not a simple vector of bytes).
Python is overrated
🤧 ohh really?
Said mostly by people who haven’t written python and shipped it to production
@@Rxlochan Said by people who force others to use this garbage in production
@@RustedCroaker What No one is forcing anyone to write only in python
Everyone before I learn python : it's the best language ever.
Everyone now : Python is trash☠️
Cython😂
All this python is slow talk is bullshit. Programming languages are tools made to do different things efficiently . You want to write something to be very fast and resource efficient go with c, c++ or rust . You want to make a backend of a website quickly go for python , php or something else . These tools are there for us to choose and use them according to our requirement. If we are writing the backend of a site in c and site has 2 visitors per day then we are just wasting our time
acha bhai
Kotlin is faster than Golang lol😂😂😂😂😂
why not this is just one aspect. When we say some language x is faster than language y, it doesn't necessary means that all the things will be 100% faster in x than y. Some things could be faster in y even though generally it is slower language in average compare to x.
@@KeshariPiyush24 lol
@@albincr yeah keep doing LOL on everything....... I guess you have ostrich syndrome.......LOL 🤡🤡🤡🤡
Let's go
👍
What an absolutely useless test lol... God benchmarks like this are so dumb. And I say this as a C++ SWE.
Interpreted languages suckkkkll
Python is 150x slower than C, but you are 35000x slower with C than with Python.