The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Over two orders of magnitude faster with YARV, yay for algorithmical optimization

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Eigen Class

Posts: 358
Nickname: eigenclass
Registered: Oct, 2005

Eigenclass is a hardcore Ruby blog.
Over two orders of magnitude faster with YARV, yay for algorithmical optimization Posted: Feb 16, 2006 5:55 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Eigen Class.
Original Post: Over two orders of magnitude faster with YARV, yay for algorithmical optimization
Feed Title: Eigenclass
Feed URL: http://feeds.feedburner.com/eigenclass
Feed Description: Ruby stuff --- trying to stay away from triviality.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Eigen Class
Latest Posts From Eigenclass

Advertisement

Did you know that YARV features magic opcodes (not enabled by default) that can perform extensive algorithmical optimization on a number of programs?

You just have to write your program*1 with some care and enable the optimizations at compile-time:

def ack(m, n)
  if m == 0 then
    n + 1
  elsif n == 0 then
    ack(m - 1, 1)
  else
    ack(m - 1, ack(m, n - 1))
  end
end

def the_answer_to_life_the_universe_and_everything
  ack(3,7).to_s.split(//).inject(0){|s,x| s+x.to_i}.to_s + "2" 
end

t = Time.new
answer = the_answer_to_life_the_universe_and_everything
sleep(0.02) # let's take a moment to ponder about the significance of that result
puts "Got THE answer (#{answer}) in #{Time.new-t} seconds."

Here's the output under a fairly recent 1.9.0

ruby 1.9.0 (2006-01-14) [i686-linux]
Got THE answer (42) in 1.815401 seconds.

And this is with YARV, Saint Valentine special edition:

ruby 1.9.0 (2006-02-14) [i686-linux]
YARVCore 0.3.3 (rev: 419) [opts: ]
Got THE answer (42) in 0.027716 seconds.

Yes, that's two orders of magnitude, just by rearranging the code a bit!

It gets even better: there's no bound to the amount of time we can save with YARV!!!

Generalization


Read more...

Read: Over two orders of magnitude faster with YARV, yay for algorithmical optimization

Topic: No RailsConf for me Previous Topic   Next Topic Topic: Tarjetas de Referencia rápida (Quick Reference Cards)

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use