Added back in basic benchmark support. To run:
ruby benchmark/benchmark.rb --adapter mysql --num 1000 ruby benchmark/benchmark.rb --adapter mysql --num 1000 --to-csv /tmp/results.csv ruby benchmark/benchmark.rb --adapter mysql --num 1000 --to-html /tmp/results.html
This commit is contained in:
parent
369a5e0e64
commit
5c287f1042
18 changed files with 509 additions and 22 deletions
69
benchmarks/lib/output_to_html.rb
Normal file
69
benchmarks/lib/output_to_html.rb
Normal file
|
@ -0,0 +1,69 @@
|
|||
require 'erb'
|
||||
|
||||
module OutputToHTML
|
||||
|
||||
TEMPLATE_HEADER =<<"EOT"
|
||||
<div>
|
||||
All times are rounded to the nearest thousandth for display purposes. Speedups next to each time are computed
|
||||
before any rounding occurs. Also, all speedup calculations are computed by comparing a given time against
|
||||
the very first column (which is always the default ActiveRecord::Base.create method.
|
||||
</div>
|
||||
EOT
|
||||
|
||||
TEMPLATE =<<"EOT"
|
||||
<style>
|
||||
td#benchmarkTitle {
|
||||
border: 1px solid black;
|
||||
padding: 2px;
|
||||
font-size: 0.8em;
|
||||
background-color: black;
|
||||
color: white;
|
||||
}
|
||||
td#benchmarkCell {
|
||||
border: 1px solid black;
|
||||
padding: 2px;
|
||||
font-size: 0.8em;
|
||||
}
|
||||
</style>
|
||||
<table>
|
||||
<tr>
|
||||
<% columns.each do |col| %>
|
||||
<td id="benchmarkTitle"><%= col %></td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<tr>
|
||||
<% times.each do |time| %>
|
||||
<td id="benchmarkCell"><%= time %></td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<tr><td> </td></tr>
|
||||
</table>
|
||||
EOT
|
||||
|
||||
def self.output_results( filename, results )
|
||||
html = ''
|
||||
results.each do |result_set|
|
||||
columns, times = [], []
|
||||
result_set.each do |result|
|
||||
columns << result.description
|
||||
if result.failed
|
||||
times << "failed"
|
||||
else
|
||||
time = result.tms.real.round_to( 3 )
|
||||
speedup = ( result_set.first.tms.real / result.tms.real ).round
|
||||
|
||||
if result == result_set.first
|
||||
times << "#{time}"
|
||||
else
|
||||
times << "#{time} (#{speedup}x speedup)"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
template = ERB.new( TEMPLATE, 0, "%<>")
|
||||
html << template.result( binding )
|
||||
end
|
||||
|
||||
File.open( filename, 'w' ){ |file| file.write( TEMPLATE_HEADER + html ) }
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue