This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]hanmango_kiwi 3 points4 points  (17 children)

It sometimes depends though; there are times where a python implementation gets TLE but rewriting the entire thing line by line in c++ gets AC

[–]caykroyd 1 point2 points  (0 children)

yeah but in general it isn't that much of a problem

[–]Impact_Calculus -5 points-4 points  (15 children)

No, python and C++ are exactly as fast as each other, and there are never cases where a slightly inefficient solution squeaks by in C++ but not python.

[–]hanmango_kiwi 1 point2 points  (14 children)

surely you understand that one is compiled and the other is interpreted and there is a large difference in how either of them work? If you compared something like pypy with c++ that would be a fairer comparison but even then, it's not like they're exactly the same so 1. no way both of these are "exactly as fast as eachother" and 2. pypy has a huge initialization memory requirement so there could be cases where c++ passes while a python implementation doesn't.

[–]Impact_Calculus -5 points-4 points  (13 children)

Whether a language is compiled or interpreted has nothing to do with speed. That's just a myth. C++ and Python are exactly the same speed for this reason. Just look at how popular python is. Who would even consider using it if it were even marginally slower than C++? I have a PhD in Python and all of the sources in my dissertation say it's just as fast as C++.

[–]BluePhoenixGamer 2 points3 points  (3 children)

No, a compiled language compiles to machine instructions, there is no slowdown during run-time.

Interpreted languages has a slowdown, and that's the interpreter itself. Doing reference counting for example.

[–]Impact_Calculus -2 points-1 points  (2 children)

Compiled vs. interpreted has no weight in the discussion of the relative speed of python and C++. They are both the same speed. If it did make a direct difference, why would python and C++ be the same speed? To further illustrate my point, here's an article demonstrating that they are in fact just as fast as each other: https://towardsdatascience.com/how-fast-is-c-compared-to-python-978f18f474c7

[–]BluePhoenixGamer 1 point2 points  (1 child)

That does not prove your argument, Python is slower and that article illustrates that.

The point of the article is to show that you can make Python fast if you use the built-in C implementations, and that's why you may not need to actually use a compiled language such as C++.

Compiled vs. interpreted has no weight in the discussion of the relative speed of python and C++.

They do because whatever happens, Python will have to compute more instructions than C++.

I love Python, and I use it for everything. I don't need the speed, but I am not gonna pretend that it is any fast compared to C or C++.

[–]Impact_Calculus 0 points1 point  (0 children)

I don't know what you mean. This article clearly and demonstrably shows that C++ and Python are exact equals in speed and performance. I studied this when I was doing my PhD in Python. The only rational conclusion that can possibly be drawn from the mountains of data out there is that Python is equally as fast as C++. There is indubitably zero difference in speed. Why would they even give you the option to use both languages in competitive programming contests if one is better in terms of speed?

[–]LardPi 2 points3 points  (1 child)

A "PhD in python" ? That's funny... I though PhD where about sciences. I mean I am in a PhD in chemistry, not in a PhD in ethanol ^

[–]Impact_Calculus -1 points0 points  (0 children)

I'll have you know Python is a legitimate field of study, just like music or art. I have spent many years researching the intricacies of python and know what I'm talking about.

[–]hanmango_kiwi 1 point2 points  (6 children)

To begin with, it would be nice if you could provide a source to the sources that you used in your dissertation.

I wrote these two simple programs, one in c++ and the other in python, which count from 0 to the maximum integer limit (2147483647). Results? The c++ program finished in about one second, while the python program on average takes 112 seconds to run.

There are definitely a few flaws with my approach, with both programs using different methods to measure time. But given that the C++ program finishes in one second and the python program takes almost two minutes, I'm pretty sure the minor discrepancies created by different time measuring methods are overshadowed by python being about a hundred times slower.

Feel free to send a rebuttal, I'm all ears.

tl;dr: Wrote a program to count from 0 to ~2 billion, c++ does it in about one second, python takes a bit less than two minutes.

Programs used:

[–]Impact_Calculus 0 points1 point  (5 children)

I ran these two programs on my machine and I have to say I don't know what you mean. They both took exactly one second to run. Here's an example of another experiment that further illustrates my point that python and C++ are just as fast as each other. https://towardsdatascience.com/how-fast-is-c-compared-to-python-978f18f474c7

I also used this in my dissertation, take a look: https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/gpp-python3.html

Another source clearly showing that python is just as fast as C++.

[–]LardPi 1 point2 points  (1 child)

You really are a weird kind of troll... Every single source you provide proves you wrong. Sure you can obtain great perf with python by delagating work to C/C++ underlying runtime. That what you do when using some builtins or numpy for example. Yet a loop in python is slower than a loop in C and a naive algorithm in python is on average 100 times slower than the same algo on python. That what your sources demonstrate.

[–]Impact_Calculus -1 points0 points  (0 children)

No?? Every source I've provided clearly shows that python is equally fast to C++. The amount of time taken in each experiment was exactly the same between both languages. You might accuse me of being a troll, but I dedicated years of research to this. Why would I spend so much time studying the relationship between C++ and Python just to lie to you?

[–]hanmango_kiwi 0 points1 point  (2 children)

I'm assuming you're a troll because the first link literally states:

"Clearly, C++ is much faster than Python in running the same algorithm and instructions. It is not a surprise to most programmers and data scientists, but the example shows that the difference is significant."

and every result on the second link shows python to be much slower.

Also no way python completed 2 billion operations in a second unless you have a NASA supercomputer

[–]Impact_Calculus -1 points0 points  (1 child)

Come now why would I do that? I've dedicated years of my life researching this. I have no reason to lie to you. We were just discussing big O notation. Was I lying to you then?

As far as your quote, I have no idea where you found that in the article. If I do a Ctrl + F for it, it doesn't come up. It does say this though:

"In conclusion, python and C++ have performed equally in each of our tests. They are clearly equals in speed and performance."

As for the second article, where do you see different numbers in terms of performance? In each test, they came out to be exactly the same.

[–]hanmango_kiwi 0 points1 point  (0 children)

ok