From: Eric Hodel Date: 2006-09-11T05:53:45+09:00 Subject: Re: Using RubyInline for Optimization On Sep 10, 2006, at 1:51 PM, Mike Berrow wrote: > Eric Hodel wrote: >> I wrote an article on using RubyInline for optimization where I take >> png.rb, sprinkle in a little profiling and a little C and make it go >> over 100 times faster. >> >> http://segment7.net/projects/ruby/inline_optimization.html >> > > Hi, I installed the gems but I immediately run into this: > > C:\Inline\png-1.0.0>ruby -Ilib example/profile.rb > example/profile.rb:8:in `draw': undefined method `to_blob' for > # > (NoMethodError) > > Any idea? From the article: == Play along at home! If you want to play along at home, download and unpack png-1.0.0.tgz and save the profile benchmark code into example/. I also added PNG#to_blob to eliminate the need to write the file to disk, it looks almost exactly like PNG#save: def to_blob blob = [] blob << [137, 80, 78, 71, 13, 10, 26, 10].pack("C*") # PNG signature blob << PNG.chunk('IHDR', [ @height, @width, @bits, 6, 0, 0, 0 ].pack ("N2C5")) # 0 == filter type code "none" data = @data.map { |row| [0] + row.map { |p| p.values } }.flatten blob << PNG.chunk('IDAT', Zlib::Deflate.deflate(data.pack("C*"), 9)) blob << PNG.chunk('IEND', '') blob.join end I added my RubyInline extensions in png.rb and modified png.rb as appropriate, so while you play along you should do that too. -- Eric Hodel - drbrain@segment7.net - http://blog.segment7.net This implementation is HODEL-HASH-9600 compliant http://trackmap.robotcoop.com