114
you are viewing a single comment's thread
view the rest of the comments
[-] Womble@lemmy.world 5 points 4 months ago

Python can be extremely slow, it doesn't have to be. I recently re-wrote a stats program at work and got a ~500x speedup over the original python and a 10x speed up over the c++ rewrite of that. If you know how python works and avoid the performance foot-guns like nested loops you can often (though not always) get good performance.

[-] FizzyOrange@programming.dev 1 points 4 months ago

Unless the C++ code was doing something wrong there's literally no way you can write pure Python that's 10x faster than it. Something else is going on there. Maybe the c++ code was accidentally O(N^2) or something.

In general Python will be 10-200 times slower than C++. 50x slower is typical.

[-] bitcrafter@programming.dev 6 points 4 months ago

Unless the C++ code was doing something wrong there’s literally no way you can write pure Python that’s 10x faster than it. Something else is going on there.

Completely agreed, but it can be surprising just how often C++ really is written that inefficiently; I have had multiple successes in my career of rewriting C++ code in Python and making it faster in the process, but never because Python is inherently faster than C++.

[-] FizzyOrange@programming.dev 1 points 4 months ago

Yeah exactly. You made it faster through algorithmic improvement. Like for like Python is far far slower than C++ and it's impossible to write Python that is as fast as C++.

load more comments (15 replies)
load more comments (16 replies)
this post was submitted on 13 Jul 2024
114 points (98.3% liked)

Programming

17314 readers
79 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 2 years ago
MODERATORS