From: Matthew Moss Date: 2006-02-24T07:35:40+09:00 Subject: Re: Huge performance gap On 2/23/06, Alexis Reigel 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...