Counting CPU Instructions in Python (blog.mattstuchlik.com)
from rimu@piefed.social to python@programming.dev on 26 Feb 2024 21:51
https://piefed.social/post/46143

Did you know it takes about 17,000 CPU instructions to print(“Hello”) in Python? And that it takes ~2 billion of them to import a module?

#python

threaded - newest

AnUnusualRelic@lemmy.world on 26 Feb 2024 22:13 next collapse

It’s fine, I’m not in a hurry.

muntedcrocodile@lemmy.world on 26 Feb 2024 22:19 next collapse

If i needed speed i wouldnt be programming in python.

eager_eagle@lemmy.world on 26 Feb 2024 22:27 next collapse

also, if I needed speed I wouldn’t be printing stuff every 100k instructions

grue@lemmy.world on 27 Feb 2024 01:31 next collapse

If I needed speed, I’d be programming in Python but then profiling the performance and re-writing the inner loops and such to call C or BLAS.

muntedcrocodile@lemmy.world on 27 Feb 2024 03:06 collapse

Surly u can use rust these days?

sugar_in_your_tea@sh.itjust.works on 27 Feb 2024 14:58 collapse

In fact, Python is still decent even if you do need speed. We compared Python and Rust for algorithm processing, and we got similar-ish numbers when using numba. Rust was certainly faster, but we would need to retrain a lot of our team, and numba was plenty fast.

Python is fast enough, and if it’s not, there are libraries to get it there.

eager_eagle@lemmy.world on 26 Feb 2024 22:26 next collapse

so 200 to 800 microseconds on a modern cpu? Fast enough.

eclecticprune@lemmy.world on 26 Feb 2024 22:35 next collapse

While the processor I’m working on right now supports 14MIPS…

Big_Boss_77@lemmynsfw.com on 26 Feb 2024 23:45 next collapse

Is it just me… or is there a lot of python hate lately?

neo@lemmy.hacktheplanet.be on 27 Feb 2024 13:56 next collapse

Nah, my personal hate of indented blocks has been there since the late 90s /s 8-)

furrowsofar@beehaw.org on 27 Feb 2024 16:13 collapse

Yes, I hate indentation as structure but I hate tracking brackets even more.

dozymoe@mastodon.social on 27 Feb 2024 02:08 next collapse

AI crowd using python probably @Big_Boss_77 @rimu

Big_Boss_77@lemmynsfw.com on 27 Feb 2024 14:16 collapse

Ahh…that makes sense. I bet you’re right.

furrowsofar@beehaw.org on 27 Feb 2024 16:21 collapse

People use Python a lot as a Matlab, Excel/VBA, or R alternative. That was my use for many years. Some of these are compute focused problems and if the dataset is large enough and the computations complex enough then speed can be an issue.

As far as loading packages and printing. Who cares. These are not computationally intensive and are typically IO bound.

furrowsofar@beehaw.org on 27 Feb 2024 15:21 collapse

Same for me. I have used Python for most things since the late 1990s. Love Python. Have always hated the poor performance… but in my case mostly it was good enough. When it was not good enough, I wrote C code.

Python is good for problems where time to code is the limiting factor. It sucks for compute bound problems where time to execute is the limiting factor. Most problems in my world are time to code limited but some are not.

Python compute performance has always sucked.

Big_Boss_77@lemmynsfw.com on 27 Feb 2024 15:35 collapse

I get that… I’m not a developer, I’m a network engineer but I use a lot of python in my day to day operations. I always took python to be the “code for non-coders” which made it infinitely more approachable than some of the other languages.

I’m not running the F1 grand prix over here, I’m driving to get groceries, so what if it’s not the fastest thing out there. Close enough is good enough for me. And in my experience that’s what people are using python for, daily driving.

andnekon@programming.dev on 27 Feb 2024 03:08 next collapse

I doubt it’s useful for performance evaluation, however, if you are writing a paper and want to compare your algorithm to an existing one, this can be handy

sugar_in_your_tea@sh.itjust.works on 27 Feb 2024 15:16 collapse

Eh, maybe? It’s probably only useful for large jumps, and timing is also probably good enough for that as well. With small jumps, instruction execution order matters, so a bigger number could very well be faster if it improves pipelining.

It’s certainly interesting and maybe useful sometimes, but it’s probably limited to people working on Python itself, not regular users.

furrowsofar@beehaw.org on 27 Feb 2024 04:41 collapse

Just remember that an optimized C program will run about 100x faster then a similar Python program in a compute bound problem. So yes Python is slow but often good enough.