this post was submitted on 12 Apr 2025
197 points (90.5% liked)

Technology

69298 readers
3851 users here now

This is a most excellent place for technology news and articles.


Our Rules


  1. Follow the lemmy.world rules.
  2. Only tech related news or articles.
  3. Be excellent to each other!
  4. Mod approved content bots can post up to 10 articles per day.
  5. Threads asking for personal tech support may be deleted.
  6. Politics threads may be removed.
  7. No memes allowed as posts, OK to post as comments.
  8. Only approved bots from the list below, this includes using AI responses and summaries. To ask if your bot can be added please contact a mod.
  9. Check for duplicates before posting, duplicates may be removed
  10. Accounts 7 days and younger will have their posts automatically removed.

Approved Bots


founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] PattyMcB@lemmy.world 53 points 2 weeks ago (24 children)

I know I'm gonna get downvoted to oblivion for this, but... Serious question: why use Python if you're concerned about performance?

[–] lengau@midwest.social 54 points 1 week ago (8 children)

It's all about trade-offs. Here are a few reasons why one might care about performance in their Python code:

  1. Performance is often more tied to the code than to the interpreter - an O(n³) algorithm in blazing fast C won't necessarily perform any better than an O(nlogn) algorithm in Python.
  2. Just because this particular Python code isn't particularly performance constrained doesn't mean you're okay with it taking twice as long.
  3. Rewriting a large code base can be very expensive and error-prone. Converting small, very performance-sensitive parts of the code to a compiled language while keeping the bulk of the business logic in Python is often a much better value proposition.

These are also performance benefits one can get essentially for free with linter rules.

Anecdotally: in my final year of university I took a computational physics class. Many of my classmates wrote their simulations in C or C++. I would rotate between Matlab, Octave and Python. During one of our labs where we wrote particle simulations, I wrote and ran Octave and Python simulations in the time it took my classmates to write their C/C++ versions, and the two fastest simulations in the class were my Octave and Python ones, respectively. (The professor's own sim came in third place). The overhead my classmates had dealing with poorly optimised code that caused constant cache misses was far greater than the interpreter overhead in my code (though at the time I don't think I could have explained why their code was so slow compared to mine).

[–] PattyMcB@lemmy.world 5 points 1 week ago (6 children)

I appreciate the large amount of info. Great answer. It just doesn't make sense to me, all things being equal (including performant algorithms), why choose Python and then make a small performance tweak like in the article? I understand preferring the faster implementation, but it seems to me like waxing your car to reduce wind resistance to make it go faster, when installing a turbo-charger would be much more effective.

[–] lengau@midwest.social 9 points 1 week ago (1 children)

I think a better analogy would be that you're tuning your bike for better performance because the trade-offs of switching to a car are worse than keeping the bike.

[–] PattyMcB@lemmy.world 5 points 1 week ago (1 children)
[–] Azzu@lemm.ee 5 points 1 week ago

Good, more people should buy bicycles

load more comments (4 replies)
load more comments (5 replies)
load more comments (20 replies)