Wednesday, September 06, 2006

Getting Started With YARV

I built YARV yesterday so that I could start playing with it. Building and installing it was easy, I just followed the directions on its home page. Testing also went pretty well (except for my last test) — the results were a bit more varied than I'd thought they'd be though. Here's what I saw.

I started out with my hokey little prime finder that I use as an example everywhere else. Here's the code


for num in 1..100_000 do
  is_prime = 1
  for x in 2..(num - 1) do
    if (num % x == 0)
      is_prime = x
      break
    end
  end
  if is_prime == 1
    puts "#{num} is a prime number"
  else
    puts "#{num} equals #{is_prime} * #{num/is_prime}"
  end
end

And here are the results:

$ time ruby primes.rb < /dev/null
real    3m12.391s
user    3m7.828s
sys     0m0.172s
$ time ~/bin/rubyyarv primes.rb < /dev/null
real    1m10.277s
user    1m7.008s
sys     0m0.084s
About a 3x speed up, pretty good stuff.

Then I whipped out a little recursive factorial function:


def fact(num)
  if num == 1
    num
  else
    num * fact(num - 1)
  end
end

1000.times do
  puts "500! is #{fact(500)}"
end

Which looked like this:

$ time ruby fact.rb > /dev/null
real    0m2.932s
user    0m2.792s
sys     0m0.008s
$ time ~/bin/rubyyarv fact.rb > /dev/null
real    0m2.230s
user    0m2.132s
sys     0m0.008s

Not nearly the speed up I'd thought I'd get. I'll have to profile it and see if I can figure out where the bottleneck is.

Then I decided to try my rwb test suite. Here's what it looked like:


$ ruby -Ilib test/test_rwb.rb
Loaded suite test/test_rwb
Started
....................................................
Finished in 0.024843 seconds.
52 tests, 95 assertions, 0 failures, 0 errors
$ ~/bin/rubyyarv -Ilib test/test_rwb.rb
Loaded suite test/test_rwb
Started
....................................................
Finished in 0.020679 seconds.
52 tests, 95 assertions, 0 failures, 0 errors

About a 20% speed-up here, not bad but not great either.

Finally, I threw the r43 test suite at it. This is where things broke down:


$ ruby -Ilib test/test_r43.rb
Loaded suite test/test_r43
Started
...............................................
...............................................
...........
Finished in 3.956994 seconds.
105 tests, 650 assertions, 0 failures, 0 errors
$ ~/bin/rubyyarv -Ilib test/test_r43b
Loaded suite test/test_r43
Started
....................EEEEEEEEEEEEEEEEEEEEE..EEEEE
................................................
......E
Finished in 0.671329 seconds.
[error messages deleted]
105 tests, 107 assertions, 0 failures, 27 errors

Either my install is broken, or there are other problems. Again, I'll have to take a longer look and see what I see. I'll try to post more about this tomorrow.

No comments: