matthew.moss.coder
2/23/2006 10:36:00 PM
On 2/23/06, Alexis Reigel <mail@koffeinfrei.org> wrote:
> Hi all
>
> I've ported the following c++ code to ruby. It is a recursive
> (backtracking) sudoku-solving algorithm. Well, I was rather surprised by
> the execution time I got:
>
> c++ code: 0.33 seconds
> ruby code: 27.65 seconds
>
> The implementation should do the same, at least they run through the
> method/function "next_state"/"nextone" both 127989 times.
>
> Now how can it be that the ruby code is so awfully slow?
> Is that normal for ruby?
> Or is my implementation so horribly bad?
> I am aware that the non-native and object-oriented ruby code won't be as
> fast as the c++ one, but I didn't expect such a gap.
Others can better speak on ruby specifics, but...
Ruby is interpreted (inefficiently?), C++ is compiled.
And the algorithm is something like O(n^3)? Or worse?
Seems like a reasonable difference to me...