New course! Every coder should learn Generative AI!
Try a free lesson+ 18
Granger actually the speed ultimately depends on your code but in almost every scenario C++ will will definitely defeat python in terms of speed( it can vary anywhere from 2x to 5x faster depending on systems and code)
As far as ML and AI is considered, people preffer python because python have complete arsenal of libraries and modules to make complicated tasks easier and also generally person working on ML project tend to have higher end systems so the performance doesn't act as a barrier there.
+ 18
One has to differentiate between development speed and execution speed.
In the discussion so far, I get the feeling the two things get mixed up.
C++ development is harder, especially if you just want to use the language and have no huge informatics background.
So it becomes a question:
Would I rather develop easily and drink coffee while execution, or do I want to sweat over the development and then get my results more quickly?
I find it impossible to make a general decision, it will hugely depend on the specific situation.
+ 11
You should ask yourself whether execution time is important for what you want to achieve.
In some cases it will make the difference between life and death e.g. if an airbag is not triggert in time.
You will also feel the need for a fast execution if you have to handle very huge amounts of data with lots of calculations.
You can safe hours, days, weeks...depending on the amount of calculations.
+ 6
Example 1:
I sometimes want to know certain things about natural language texts, like novels.
I have slammed a dozen of them into one fat txt file, and then did operations:
Extract everything that's not a letter, split it into words, count how often each word occurs, list it up... stuff like that.
Whole operation took like one second on my seven year old machine. In Python.
I do have a second.
If I wanted to analyze a hundred novels, I'd empty the dishwasher in-between.
So why would I ever want to wreck my brain doing the same in a close-to-the-metal language?
Example 2:
I wrote a chess board in Brython, which is yet slower than regular Python.
When you move a stone, you sometimes have to wait for a second.
Then I wanted to cook up a primitive AI for that.
After I got it to one-move check mate finding skill, it needed between 3 and 30 minutes per move.
Yeah... that doesn't fly. 😉
I'm sure it could have been quicker if I knew what I was doing...
But it serves to demonstrate that it depends.
+ 5
1 second can become an eternity, if you're driving an autonomous car... Nobody cares of a second in a small web store. I'm not a friend of everybody learning C* since it requires to be very accurate, but for some cases, it's just necessary.
+ 5
Yeah, exactly.
As long as it's not one of the cases where you suddenly realize:
'Aaah, that's why!'
As a user, I get really annoyed when I have to wait for stuff to happen.
Microsoft Office is an example.
(Although I doubt that's written in Py. 😅)
+ 4
Python fast to write and compile but slow in use when installed unlike Java and c++.
+ 3
Python is easier and has a lot of very useful libraries.
In terms of speed , Look at the worst case not the best. In an low-end devices , Python is really slow..Especially in ML.
The difference is more as the size of code increases
+ 3
Granger Yes. In my device , ML takes 5-6 seconds to load anything.
+ 3
Granger ,
codemonkey is saying that you have to run the code for very big inputs to actually see a visible difference in time.
+ 3
Python was not designed to be fast but rather designed to make development more efficient and faster
Just look at how "Hello World" is written in different languages:
C++:
#include <iostream>
using namespace std;
int main(){
cout<<"Hello World";
Return 0;
}
But in Python:
Print("Hello World")
Ofcoure 1 second is not slow for people like you or me but for those who care about user's satisfaction,it might be
Even my Python codes run within 2 or 3 seconds😅
So it depends on what are you focusing on:
fast execution or fast development
+ 1
C++ is compiling to binary code and optimizing by the compiler. Binary code runs as fast as your processor. (For example, multiplication of two numbers on my phone is faster than 1 ns!)
+ 1
C++ is faster than other languages.
0
Use multithreading and a 32 bit app will run like 128 bit ..
0
Qqw inl
0
It depends on who's using your code or software and what kind of hardware they're using.
A lot of people use the cheapest laptop they can get that is able to run the software they need to use.
As almost anyone knows, the minimum requirements for most software is able to run that software at a very slow speed.
Python is easier to learn and code written in it should be easier to maintain than code written in C++.
So it's a trade-off. Depends on what application your software is being used for. And also what kind of hardware you expect your user to be using.
0
Where the speed hits strong is in multi-threading, gaming, rendering and all stressing heavy work for CPU
python good for little programs like console utilities as in Linux shell
0
python uses the FORTRAN and C compilers to speedup the execution of matrix operations and Data Science operations. So it is fast in this scenario.