4 ms·
> it won second place Out of how many? While I'm pretty sure you're a very competent programmer, there's a possibility others used non-optimal algorithms. A
by 2143 4y ago
> it won second place
Out of how many?
While I'm pretty sure you're a very competent programmer, there's a possibility others used non-optimal algorithms.
A good algorithm in a slow language can, on the limit, be faster than a bad algorithm in a faster language.
Case in point: Norvig's sudoku solver in Python blows everything else away in performance because he put a lot of thought into the algorithm [1]. I wrote a C program to solve sudoku (using a backtracking approach), and it was nowhere as fast as Norvig's python program. Can anybody conclude python is therefore faster than C? No! The only thing you can conclude from that is that I'm a lousy programmer :)
Sure you can reimplement Norvig's program in Rust or C or assembly or Brainfuck or whatever, but that's besides the point.
[1] https://norvig.com/sudoku.html https://norvig.com/sudoku.html
- atoav 4y ago> Out of how many? 20 or so. It has been a while ago so I cannot recall the exact way I did it, but I certainly didn't implement any specific algorithm, I just did the straightforward thing using Rusts builtin functions as a realistic emulation of a lazy programmer. The point of my comment was not to claim that Rust is the faster language. The point was that you can write mediocre Rust and still end up with extremely performant code that covers a lot of ground.
- randrews 4y agoMy experience exactly. I wrote an emulator in Rust for a thing implemented on an FPGA that generates a video signal. For the first pass, I just ported the Verilog code to Rust, essentially: big loop over all the pixels every frame, figure out which color it should be, return that. There are a ton of ways to factor things out of that so you're not doing repeated reads of stuff, and I was going to gradually put them in until it was fast enough... And then the naive solution ran at 100 fps. So uh. Okay then. I see the value in Rust now.