February 12th, 2020 at 5:25 AM
Quote:Someone else did another deep dive into this very same problem, and posted their findings and code.Based rustposter.
A friend lent me a book on it a month ago or so, it's incredible how fast LLVM can be compared to C, in a few tests I've found that it compiles even better than C.
That being said, if you do want to make it extremely fast, then you also need to wrap everything in unsafe{} which scares the shit out of every rust developer.
Cool that you added concurrency though. I was never able to get a good grasp of that, especially when trying to make everything asynchronous. Spawning threads that do stuff was the easy part, but making sure they didn't interfere with each other was a whole other issue. To be fair I only really ever did try in C++ and Java, both of which seemed a lot more complicated than what Python does here.
Do you reckon that removing all the time benchmarking would improve performance at all? I know that most of it's just fetching values and doing arithmetic, but you do it in each call to palindromes() and main() which I'm assuming would add up to a lot of extra instructions. Perhaps remove them and just run the script in the linux 'time' pipeline?
Code:
time python script.py
Otherwise, your optimization is probably as good as it's gonna get. Then again, I'm no math major, but it seems there's a lot less of a pattern for finding palindromes than, say, finding prime numbers.