Speed comparison between C++ and Python for a program that counts to 1,000,000,000.
@wholyv4K followers
914,625 views
41 Comments
Comments from the original post on X (Twitter)

@glugalug
2.4s? Was your C++ binary writing all those numbers to the console?
64 likes

@wholyv
Nope, not at the console. In both programs (in C++ and Python), only a for loop was established, and the final output, i.e., 1 billion, was outputted to the console.
27 likes

@Daedalus_Sy
I’m too old to put up with that nonsense anymore. I’d rather perfect the programs appearance and logic in Python then convert and optimize portions or the entire program later. Speed during design and development is a metric that matters far more than execution speed during design and development phase. You can figure out if a program and workflow will work with real users MUCH FASTER with a language like Python. Anything can be optimized and/or rebased later.
55 likes

@Iluvalar1
You clearly made a mistake and did a poor job in your python code.
47 likes

@matthew_meadows
Stupid engagement bait for weak programmers.
23 likes

@adi_verse1
If I'm not wrong it mostly shows C++ compiler optmizn deleting empty loops, vs .py intrptr overhead. Running python through PyPy or NumPy narrows that gap instantly. Great example of compiled vs. intrptr design though
18 likes

@wholyv
@Adi_Verse_ performance critical parts are implemented in C in numpy.
9 likes

@0xKNiraj
This means nothing without also posting the source code used.
17 likes

@wholyv
Code used (C++): int main() { size_t n = 0; while (n < 1'000'000'000) n++; std::cout << n << std::endl; } Code used (Python): n = 0 while (n < 1000000000): n += 1 print(n)
26 likes

@AIRobin_net
only 0.2 sec with python here
14 likes

@AppreciatorWay
Now do machine language.
8 likes

@rudharcom
The optimising phase of the C compiler sees that the program produces no output, so all the counting can be optimised out, or at least replaced by just setting the variable to the end value.
6 likes

@caveman2ez
Complines down to; C++ --> Machine Code Python --> C++ --> Machine Code
6 likes

@HbgHbg1010
Show the code because that looks just like compiler optimization. C loops should be faster regardless but like not THAT fast
6 likes

@TopCurlsoid
Apples and oranges. ASM will have C++ eating its dust.
5 likes

@wholyv
I code in ASM. difference of speed between C and ASM is not even noticeable. even tho asm is obviously faster. to humans, gap between <1s and <2s is irrelevant.
31 likes

@Apar_maker
@TopCurlsoid People who don’t see real value behind the different purposes of languages they use are easily measuring the things they understand; speed, time or delay. But if that is necessary to have just a loop like that, why don’t you write it as asm function and call it from Python prog?
8 likes

@TopCurlsoid
@wholyv Precisely. And if you need to optimize coefficient's of a horner's scheme, use Python, not C or ASM.
3 likes

@sable_apathy
are we serious still doing this? in 2026?
5 likes

@TechWeaponX
🐍 is still better for ML
5 likes




















