Skip to content

Instantly share code, notes, and snippets.

@christiangenco
Created December 16, 2015 19:25
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 christiangenco/024f9262a586eed5cd1d to your computer and use it in GitHub Desktop.
Save christiangenco/024f9262a586eed5cd1d to your computer and use it in GitHub Desktop.
# ruby herokuspeed.rb > herokuspeed.html && open herokuspeed.html
require 'pry'
require 'descriptive_statistics'
require 'erb'
# require 'open3'
def time_exec(cmd)
start = Time.now
`#{cmd}`
Time.now - start
end
@data = {}
@data = {"chunkhost"=>[0.190836428, 0.135945516, 0.135317304, 0.119732387, 0.122785909, 0.099232159, 0.134818396, 0.093863217, 0.127336203, 0.136375393, 0.1409528, 0.074119053, 0.112784714, 0.076117759, 0.110166855, 0.199103617, 0.069521835, 0.113484899, 0.072057439, 0.083044963, 0.108349443, 0.079935423, 0.105514038, 0.119017488, 0.122039883, 0.077895915, 0.084028433, 0.098272508, 0.075550463, 0.068594591, 0.071887891, 0.22982994, 0.094690258, 0.072988292, 0.088186376, 0.067440576, 0.093832045, 0.079304099, 0.099971912, 0.081297774, 0.098043278, 0.077788212, 0.111412734, 0.153003262, 0.075596723, 0.064362513, 0.100003829, 0.103179929, 0.091976673, 0.09199386, 0.083612097, 0.086778842, 0.080375427, 0.082537779, 0.181814783, 0.159005167, 0.090204826, 0.090571481, 0.077587121, 0.091956533, 0.09732266, 0.085407511, 0.10112524, 0.070964171, 0.076595245, 0.112541303, 0.082664942, 0.082343899, 0.097391712, 0.134598319, 0.104046834, 0.104210184, 0.079060292, 0.103724802, 0.101566153, 0.071118709, 0.466473122, 0.082425438, 0.072704974, 0.096385899, 0.065260364, 0.084439465, 0.085918049, 0.161604165, 0.082208313, 0.079338483, 0.109166787, 0.075274644, 0.088456276, 0.098688015, 0.068072548, 0.101966307, 0.074590261, 0.076011035, 0.074275376, 0.105991707, 0.100402975, 0.097750003, 0.08876822, 0.118478649], "google"=>[1.60321406, 0.150679093, 0.160946695, 0.162865118, 0.15951901, 0.147695983, 0.131983281, 0.190237364, 0.161116145, 0.157901014, 0.139787225, 0.156415935, 0.113776736, 0.148512033, 0.130746968, 0.162804685, 0.108002045, 0.125441296, 0.11467364, 0.126219701, 0.120430105, 0.158298845, 0.15632995, 0.125094723, 0.150865319, 0.09677245, 0.10762904, 0.128491574, 0.127078912, 0.107492097, 0.112918519, 0.16100371, 0.131735063, 0.109818415, 0.134190103, 0.126356772, 0.119561509, 0.127540401, 0.131376559, 0.115712959, 0.129596643, 0.113098504, 0.103305471, 0.133114573, 0.098071305, 0.105038866, 0.129817983, 0.166058285, 0.133820518, 0.139901489, 0.114217538, 0.109241292, 0.133906345, 0.11426165, 0.105918126, 0.107109281, 0.110431436, 0.103769308, 0.125831883, 0.106282443, 0.101634298, 0.100215211, 0.122184988, 0.100715647, 0.124868321, 0.125662527, 0.13126993, 0.103569165, 0.12792207, 0.108315579, 0.129935817, 0.119306795, 0.099360499, 0.127146849, 0.127872839, 0.135563811, 0.130238858, 0.10790425, 0.108137176, 0.137161305, 0.126048751, 0.132422563, 0.134726686, 0.112749292, 0.129103505, 0.105144142, 0.120315535, 0.136625763, 0.130175094, 0.124390283, 0.13392887, 0.130870388, 0.118638401, 0.120260544, 0.121380874, 0.101498255, 0.106166469, 0.102900736, 0.122190828, 0.13255968, 0.133677836, 0.112049406, 0.12167405, 0.122582173, 0.100833764, 0.134597283, 0.229894347, 0.128381118, 0.292808114, 0.103573501, 0.097603634, 0.116722667, 0.104618125, 0.101895829, 0.106799138, 0.126731568, 0.129474441, 0.101289339, 0.125868632, 0.111436587, 0.098922759, 0.129442231, 0.133949671, 0.107850002, 0.108001092, 0.143047706, 0.102298821, 0.134564349, 0.126691369, 0.105405269, 0.101607875, 0.116685598, 0.123808036, 0.100408031, 0.103054615, 0.135003354, 0.106284846, 0.164398391, 0.153657473, 0.15820107, 0.113169054, 0.097892942, 0.133054277, 0.10297678, 0.120045152, 0.114989851, 0.112221057, 0.128673919, 0.12335214, 0.128958612, 0.106762144, 0.167784635, 0.133730863, 0.102369917, 0.130589929, 0.134524541, 0.105484623, 0.13297665, 0.098436048, 0.132115612, 0.10549716, 0.167847311, 0.110490418, 0.107502166, 0.122613234, 0.138262224, 0.126094223, 0.102628554, 0.113634584, 0.1113353, 0.128804327, 0.109511099, 0.136894828, 0.1148813, 0.126346376, 0.112387315, 0.09859423, 0.119335752, 0.135855991, 0.138186676, 0.128407249, 0.109016637, 0.104837935, 0.116699191, 0.110747864, 0.130253547, 0.114525155, 0.121026526, 0.154071323, 0.131288542, 0.104512653, 0.097927178, 0.112011583, 0.11349202, 0.136635988, 0.123248106, 0.100045619, 0.131283747, 0.119127736, 0.1194968], "heroku"=>[1.024207444, 1.19893899, 1.053298525, 1.13624676, 1.105097217, 1.096394717, 1.033273166, 1.159049766, 1.171636828, 1.100351209, 1.05455218, 1.251186952, 1.116080523, 1.055105114, 1.041834772, 1.18842077, 1.168382665, 0.998982438, 1.164206843, 1.180823924, 1.056105694, 0.998066043, 1.055664177, 1.075378144, 0.998873133, 1.085850479, 1.098368223, 1.08043975, 1.204660581, 1.159699482, 1.133632692, 1.115167548, 1.310677361, 1.109577343, 1.025298226, 1.111863556, 1.060340767, 1.11654275, 1.171146255, 1.106530999, 1.000822959, 0.98010134, 1.087265504, 1.120552902, 1.169818803, 1.064693865, 1.080547023, 1.1097714, 1.082735869, 1.050266049, 1.146153603, 1.276622698, 1.257896088, 1.111590979, 1.139361391, 1.344858562, 1.150836289, 1.144774682, 1.065918575, 1.103298932, 1.067093686, 1.099318662, 1.07117294, 1.101940851, 1.184228802, 1.098003875, 1.102243319, 1.101091179, 1.132143582, 1.268388996, 1.288011989, 1.097805183, 1.170551907, 1.202014952, 1.087846837, 1.159107956, 1.124321388, 1.060011734, 1.009095796, 1.03053431, 1.820398316, 1.117269304, 1.089801555, 1.285370791, 1.089727723, 1.10857188, 1.080037227, 1.413980931, 1.116307837, 1.050473913, 1.140159719, 1.143119574, 1.048507375, 1.078596451, 1.120976949, 1.185240268, 1.082579507, 1.135460823, 1.183999581, 1.103818872]}
if @data.empty?
n = 100
n.times do
(@data["chunkhost"] ||= []) << time_exec("curl https://dbinbox.com -o /dev/null -s")
(@data["google"] ||= []) << time_exec("curl https://google.com -o /dev/null -s")
p @data
end
n.times do
(@data["heroku"] ||= []) << time_exec("curl https://dbibox.herokuapp.com -o /dev/null -s")
(@data["google"] ||= []) << time_exec("curl https://google.com -o /dev/null -s")
p @data
end
binding.pry
end
# exit
##########################################
@whisker_data = {}
@data.each{|k, values|
@whisker_data[k] = values.descriptive_statistics.values_at(:min, :q1, :q3, :max)
}
erb = ERB.new(DATA.read)
puts erb.result(binding)
__END__
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
<% @whisker_data.each do |key, values| %>
['<%= key %>', <%= values.join(',') %>],
<% end %>
// Treat first row as data as well.
], true);
var options = {
legend:'none'
};
var chart = new google.visualization.CandlestickChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment