Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "rubygems"
- require "json"
- class Stat
- attr_reader :times
- def initialize(times)
- @times = times
- end
- def mean
- @mean ||= times.inject(0) { |sum, t| sum + t } / size
- end
- def size
- @size ||= times.size
- end
- def sorted
- @sorted ||= times.sort
- end
- def median
- sorted[size / 2]
- end
- def max
- sorted.last
- end
- def min
- sorted.first
- end
- def stddev
- Math.sqrt(times.inject(0) { |sum, t| sum + (mean - t) ** 2 } / size)
- end
- def inspect
- {
- :call_count => size,
- :mean => print_float(mean),
- :median => print_float(median),
- :stddev => print_float(stddev),
- :max => print_float(max),
- :min => print_float(min)
- }.inspect
- end
- def print_float(float)
- ("%.5f" % float.to_f).to_f
- end
- end
- firefox = JSON.parse(File.read("firefox.json"))
- android = JSON.parse(File.read("android.json"))
- commands = (firefox.keys + android.keys).uniq.sort
- commands.each do |command|
- puts "#{command}: \n"
- if ff_times = firefox[command]
- puts "\tfirefox : #{Stat.new(ff_times).inspect}"
- else
- puts "\tfirefox : not called"
- end
- if a_times = android[command]
- puts "\tandroid : #{Stat.new(a_times).inspect}"
- else
- puts "\tandroid : not called"
- end
- end
Add Comment
Please, Sign In to add comment