On 2/23/06, Bill Kelly <billk / cts.com> wrote:
> From: "William James" <w_a_x_man / yahoo.com>
> > Alexis Reigel wrote:
> >> Stephen Waits wrote:
> >> > E. Saynatkari wrote:
> >> >
> >> >>
> >> >> Post the code somewhere, there might be room for improvement
> >> >> in the algorithm though it will still be considerably slower.
> >> >
> >> >
> >> > It looks, to me, like he attached his code to the OP.
> >> >
> >> > Regardless, it doesn't matter.  Algorithmic improvements may help both
> >> > the C++ and Ruby versions - but it's not going to change the fact that
> >> > one is a relatively low-level language, compiled to native machine code,
> >> > and the other is an interpreted dynamic language.  To compare them is
> >> > either ridiculous, or more likely in this case, simply ignorant.
> >> >
> >> > --Steve
> >> >
> >> Why should that be ridiculous or ignorant?
> >> I stated that I was aware of the differences between interpreted and
> >> compiled languages. But that does not change the fact that I believe
> >> that this does not explain the performance gap. An execution time of
> >> 27.65 seconds against 0.33 seconds is not just nothing is it? It's a
> >> factor of over 80 times. Besides, I implemented the same code in java
> >> too, which isn't native code
> >
> > More ignorance.  Java has a JIT compiler which produces
> > machine code.
>
> Alexis,
>
> This is usually a friendly community, by the way.    :rolleyes:
>
> But yes, it's harder to make a language like Ruby, which is highly
> dynamic at runtime, fast like C++ and Java, which are primarily
> statically compiled.  The Smalltalk folks have reportedly done pretty
> well though, so there exists the possiblilty that Ruby may get
> substantially faster in the future.  YARV is already making some
> headway.
>

Yep. YARV does do better on this test:

# YARV 0.4.0
e:\yarv\bin\ruby sudoku-solver.rb
time elapsed: 18.953 sec.
count: 127989
3 6 2 4 9 5 7 8 1
9 7 1 6 2 8 5 3 4
8 5 4 1 3 7 9 6 2
2 9 3 5 6 4 1 7 8
5 1 7 3 8 2 4 9 6
6 4 8 9 7 1 2 5 3
7 2 9 8 1 3 6 4 5
1 8 5 7 4 6 3 2 9
4 3 6 2 5 9 8 1 7

# Regular ruby 1.8.4
ruby sudoku-solver.rb
time elapsed: 27.812 sec.
count: 127989
3 6 2 4 9 5 7 8 1
9 7 1 6 2 8 5 3 4
8 5 4 1 3 7 9 6 2
2 9 3 5 6 4 1 7 8
5 1 7 3 8 2 4 9 6
6 4 8 9 7 1 2 5 3
7 2 9 8 1 3 6 4 5
1 8 5 7 4 6 3 2 9
4 3 6 2 5 9 8 1 7