Week 4 Extra Credit Test
Hey everyone! If you’d like to do the extra credit problem, here is a test that you can use to benchmark your solution:
require 'digest/md5'
require 'test/unit'
def test_encode_alac_speed
in_filename = 'test/data/3db65f4f0e1b01a3307c3c2c2ddedbb7.wav'
out_filename = 'test/data/out.raw'
assert_equal('3db65f4f0e1b01a3307c3c2c2ddedbb7',
Digest::MD5.hexdigest(File.read(in_filename))
)
File.open(in_filename, 'rb') { |file|
File.open(out_filename, 'wb') { |outf|
while data = file.read(4096 * 2 * 2)
outf.write(Week4.encode_alac(data))
end
}
}
assert_equal('62047625a959a52469e81a90d852329e',
Digest::MD5.hexdigest(File.read(out_filename)))
end
You’ll need to drop this file in to the test/data directory. But watch out, the file is 29MB. It took about 64 seconds to process on my machine. The extra credit is to make the encode_alac method faster, and to make the method work with Ruby 1.9. There will be a prize for the fastest implementation as well as a prize for a Ruby 1.9 implementation.
I will also come up with a solution and throw it in to the mix. Good luck, and have fun!
April 23rd, 2008 at 12:14 am
Well, Benchmark was a waste of time and RubyProf seems to spin into infinity for me. These were my “establish a beachhead” approach to figuring out where to spend my optimizing time (e.g. WTF is taking the most time in the 1st place, eh?
Anyone else have any luck with either of these (or come up with another) profiling tool to start zeroing in on where the cycles are being spent?
–Garrick
April 23rd, 2008 at 1:40 pm
I think we’ll discuss profiling this more in class tonight!
April 23rd, 2008 at 2:08 pm
Must have been late last night;) I got it running ok with the smaller data file
included in the test data. Based on what’s going on here, my first thought is to see if there’s a reasonable replacement or optimization for Fixnum plus operator and perhaps think about how we’re using String indexing.
%total %self total self wait child calls Name
/opt/local/lib/ruby/gems/1.8/gems/ruby-prof-0.6.0/lib/ruby-prof/abstract_printer.rb:26: warning: treating Symbol as an integer
——————————————————————————–
/opt/local/lib/ruby/gems/1.8/gems/ruby-prof-0.6.0/lib/ruby-prof/abstract_printer.rb:30: warning: treating Symbol as an integer
/opt/local/lib/ruby/gems/1.8/gems/ruby-prof-0.6.0/lib/ruby-prof/abstract_printer.rb:30: warning: treating Symbol as an integer
100.00% 0.00% 0.39 0.00 0.00 0.39 0 #encode_alac (./lib/week_4.rb:23} ./lib/week_4.rb:23
0.06 0.06 0.00 0.00 32768/32768 Fixnum#|
0.00 0.00 0.00 0.00 1/1 Fixnum#==
0.00 0.00 0.00 0.00 2/2 String#length
0.08 0.08 0.00 0.00 40960/40960 Fixnum#+
0.05 0.05 0.00 0.00 24578/24578 String#[]=
0.08 0.08 0.00 0.00 40960/40960 String#[]
0.03 0.03 0.00 0.00 16384/16384 Fixnum#&
0.03 0.03 0.00 0.00 16384/16384 Fixnum#>>
0.02 0.02 0.00 0.00 8193/8193 Fixnum#<
0.03 0.03 0.00 0.00 16384/16384 Fixnum#<<
0.00 0.00 0.00 0.00 1/1 Kernel#dup
-Garrick