Skip to content

Instantly share code, notes, and snippets.

@jelder
Created April 27, 2013 00:00
Show Gist options
  • Save jelder/5471234 to your computer and use it in GitHub Desktop.
Save jelder/5471234 to your computer and use it in GitHub Desktop.
( while :; do date ; /usr/bin/time heroku run false ; sleep 1; done ) 2>&1 | ruby parse_bench.rb
#!/usr/bin/env ruby
samples = []
STDIN.lines.each do |line|
next if line =~ /^stty/
next if line =~ /^Running/
if line =~ /real.*user.*sys/
real,_,user,_,sys = line.strip.split(/\s+/)
samples << [Float(real),Float(user),Float(sys)]
end
end
def percentile(values, percentile)
values_sorted = values.sort
k = (percentile*(values_sorted.length-1)+1).floor - 1
f = (percentile*(values_sorted.length-1)+1).modulo(1)
return values_sorted[k] + (f * (values_sorted[k+1] - values_sorted[k]))
end
puts percentile(samples.map{|s|s[0]}, 0.95)
puts "#{samples.length} samples"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment