Skip to content

Instantly share code, notes, and snippets.

@felipec
Created October 2, 2010 19:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felipec/607899 to your computer and use it in GitHub Desktop.
Save felipec/607899 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
$TEST_PERIOD = 60 * 61
$SAMPLE_PERIOD = 60 * 10
$CAPACITY = 1320
$RS = 20
class Array
def mean
self.inject(0) { |sum, x| sum + x } / size.to_f
end
def stddev
Math.sqrt(self.inject(0) { |sum, x| sum + (x - mean) ** 2 } / size.to_f)
end
def stderr
stddev / Math.sqrt(self.length)
end
end
def get_capacity
(`i2cget -y 2 0x55 0x0c w`.to_i(16) * 3570) / $RS / 1000
end
def mean_and_se(array)
return array.mean, array.stderr
end
def run_measure(title)
count = 0
@samples = []
@monitor = Thread.new do
last = nil
while true do
c = get_capacity
@samples << last - c if last
last = c
sleep($SAMPLE_PERIOD)
end
end
yield
@monitor.kill
puts "== #{title} =="
puts "samples: %s" % @samples.join(", ")
@samples.map! { |x| x.to_f * 60 * 60 / $SAMPLE_PERIOD }
puts "drain: %.2f±%.2fmA" % mean_and_se(@samples)
puts "life: %.2f±%.2fh" % mean_and_se(@samples.map { |x| $CAPACITY / x })
end
sleep(10)
run_measure("baseline") do
sleep($TEST_PERIOD)
end
@base_dir = "/home/user/MyDocs/test-music/"
@flac_file = @base_dir + "The XX - Islands.flac"
@mp3_file = @base_dir + "Interpol - Who Do You Think.mp3"
@vorbis_file = @base_dir + "Gorillaz - Last Living Soul.ogg"
@commands = [
{:name => "av flac", :file => @flac_file, :pipe => "flacparse ! avdec"},
{:name => "flac", :file =>@flac_file, :pipe => "flacdec" },
{:name => "av mp3", :file =>@mp3_file, :pipe => "mp3parse ! avdec" },
{:name => "nokiamp3", :file =>@mp3_file, :pipe => "mp3parse ! nokiamp3dec" },
{:name => "av vorbis", :file =>@vorbis_file, :pipe => "oggdemux ! avdec" },
{:name => "vorbis", :file =>@vorbis_file, :pipe => "oggdemux ! vorbisdec" },
]
@commands.each do |e|
run_measure(e[:name]) do
system("./gst-loop #{$TEST_PERIOD} filesrc location='#{e[:file]}' ! #{e[:pipe]} ! pulsesink")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment