Skip to content

Instantly share code, notes, and snippets.

@direvius
Created August 20, 2012 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save direvius/3405000 to your computer and use it in GitHub Desktop.
Save direvius/3405000 to your computer and use it in GitHub Desktop.
percentile
#!/usr/bin/env ruby
def parse_line line
fields = line.split
return fields[1], fields[3]
end
def percentile(level, values)
return values.sort[values.length*level/100]
end
stat = Hash.new
STDIN.each{|line|
key, value = parse_line(line)
if stat.has_key?(key)
stat[key] << value.to_i
else
stat[key] = Array.new << value.to_i
end
}
stat.each_pair{|k,v|
puts "#{k}\t#{v.length}\t#{percentile(ARGV[0].to_i, v)/1000} ms"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment