Python vs C++ Speed Comparison

preview_player
Показать описание
Lets compare the performance of c++ vs python counting to 1 Billion...Why is python so slow?
Рекомендации по теме
Комментарии
Автор

You can highly optimize the Python code by setting n = 1 billion before the loop begins.

ProgThoughts
Автор

I am really surprised that Python was only about 50 times slower.

zui
Автор

This is a great showcase of how much python has improved over the years, I mean this would probably not finish a few years ago.

jesse
Автор

Fun fact: the -O2 flag on the gcc compiler will most likely optimize the C++ program to the point that the result is immediate…because it generates machine code that just puts the number 1, 000, 000, 000 directly into the CPU register rather than actually counting anything. At least this is what happened when I tried it with plain C.

estrogeneral-intelligence
Автор

I told one of my professors that python was probably the best language to learn about parallelism and concurrency. He looked like I just admitted to support dog fighting. I then told him that python was so slow and inefficient, you would be able to visibly see the time difference from running on multiple threads. He laughed.

ethannelson
Автор

You see, Python is actually good since it gives you time to get a glass of water, do something, play a game, graduate and get a diploma, get a job, witness the year 3000, all while the compiler is doing its thing.

lloyd
Автор

The catch: it doesn't include compiler optimizations on C++ part. Otherwise it would probably turn into just "cout <<

MrEgorchikZ
Автор

I had never delved into programming before, but this seemed so straightforward that I couldn't resist giving it a try. Using VS Code, I successfully executed it! Thank you; it was an enjoyable experience!

mikuch_ws
Автор

I once tried counting to 1 Billion in my head.
It took me a few centuries.
I am glad I finally finished with that.

filipburcevski
Автор

the semicolon in python is just perfect as someone who write in C++

adrianprayoga
Автор

Tip: You can use underscores in Python to separate numbers. Example: 1_000_000_000

cerulityk
Автор

I didn't see printed char on console. How we can check this two examples are equivalent?

godofclash
Автор

I studied C++ and C# in university, but before that I was learning python (through online courses) for exam. Now it is funny to remember how teacher said that if we won’t optimise our code, it will calculate for longer than the exam lasts

vivngmp
Автор

You might think that the major time difference was because he used different coding languages, but python would’ve been way faster if he just removed a few zeros.

LD-dtsk
Автор

So how do they compare with for loops instead of while loops?

ADEpoch
Автор

Hey give Python a break! I bet you can't count to a billion that quickly!

richardhoyle
Автор

Sometimes you don’t need the program to run quickly. You just need it to run. That’s why I love Python. Although it’s certainly not the fastest language, its ease of use is great for beginners, and I can write a program quicker in Python than I can in c++. I don’t think I would be a programmer if Python didn’t exist, quite honestly. And keep in mind I love C++ too just for different reasons.

silverasdf
Автор

Whe do you use postincrement? Isn't it more effective to use preincrement?

skotch_izolentovich
Автор

I'm actually planning to work on a Python-like compiled programming language soon. This video remotivated me. Thank you

tigrankhachatryan
Автор

Isn't For Loop like twice as fast compared to While Loop in Python? C++ would still obviously win but I believe Python's score would look better.

ThatOpinionIsWrong