
Ask HN: 0.25s to run first 50 Euler solutions. Interesting or not? - dhbradshaw
Not too long ago, I decided to finally become comfortable with Rust. So I read through the new Rust book and used Rust to solve the first 50 project Euler problems.<p>Here&#x27;s the part that I think is interesting:<p>As I progressed through the problems, I started noticing that people were posting run times along with their code. So I joined in and began posting my run times with each bit of code.<p>Of course, once you&#x27;re posting a performance-related number, you&#x27;re playing a game and that gets a bit addictive. I started trying not just to solve the problems but to make the solutions fast.<p>After I completed the first 50 problems, which was the original goal, I measured total runtime for all 50 problems. It was just under 2 seconds. Seeing that new number led me to go back to improve the slow solutions. On some I was pretty stuck so I went to the Euler forums for ideas. In two cases, I found algorithm improvements that bought me factors of perhaps 100.<p>Plucking low-hanging fruit brought the total time quickly down to about 0.5 seconds. Wrestling brought it down from there to under 0.25 seconds. For example, for p14 I never did find any real algorithm improvements, but gradually brought it down to 29ms by speeding up the implementation. I changed implementation details on faster solutions, analyzed bounds, etc. and generally climbed further up the tree.<p>I think it would be fun to open up the code on Githup and see if together we can get down to 0.1 or 0.05 seconds. Also, I think the code can be made prettier and more Rust idiomatic without slowing down. Anyway, I was thinking of writing up a lessons learned post and making a general invite. But before spending the time, I wanted to see if there would be any interest. So ... would anyone be interested in reading a lessons learned post if I were to write one?<p>* All times are on my HP 7z laptop. Specs: AMD Dual-Core A9-9410 APU (2.9 GHz, up to 3.5 GHz, 1 MB cache)
======
steveklabnik
People on the users' forum or on the Rust subreddit might be interested!

~~~
dhbradshaw
Thanks for reaching out. And thanks for pointing to the users' forum. I've now
joined. (Was already listening on the Rust subreddit.)

