Slow and fast languages | SoloLearn: Learn to code for FREE!

+11

Slow and fast languages

What do you think is a slow language? Everyone says "Python is so slow, better C++". I don’t deny that C++ is very powerful, but how much time do you save using C++? It's not just about Python, but about any language. I'm not nitpicking, I want to know what is "slow" in your understanding. On my laptop, these codes run quickly, is 1 second really long? And I'm not talking about print ("Hello world"), but about Dataframe objects, the Titanic 1313x7 work (even half a second does not pass, I just started it). I just know that compiled languages ​​are faster than interpreted ones, but I don't know how fast C++ can run if Python is fast.

7/24/2020 1:47:36 PM

Granger

29 Answers

New Answer

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

+6

Granger, again, it would depend on the situation. Are you writing for a powerful computer? Or are you writing for most computers/users, so also for those with an outdated webbook and a bad internet deal? And also what sort of software it is. No one would recommend writing an AAA game in Python.

+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

I know there is going to be a nightmare)) but why then does AI use this slow Python when this super fast C++ can be used?

+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 that's because python is much higher level language than C++ that is, it is much difficult for system to translate python to binary than compared to C++

+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

Arsenic, I'm talking about another answer

+3

codemonkey, Ahh, got it, thanks) but still it seems to me that using C++ for these purposes is a little suicidal)))

+3

HonFu, As I understand it, the point of all this is - why use a difficult language if we can do almost the same thing in an easy one? (sorry, I almost understood the translation myself, and the translator started talking about cleaning the dishwasher🗿)

+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

+2

HonFu, Got it. But with a powerful PC, as I understand it, it doesn't really matter, right?

+1

Arsenic, That is, C ++ runs fast on almost any device, but Python only runs on powerful ones?

+1

codemonkey, I didn't understand the message a bit (I'm not very friendly with English), do you mean that Python is only for non-programmers?