# frozen_string_literal: true
require 'erb'
module OutputToHTML
TEMPLATE_HEADER = <<"EOT"
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.
EOT
TEMPLATE = <<"EOT"
<% columns.each do |col| %>
<%= col %> |
<% end %>
<% times.each do |time| %>
<%= time %> |
<% end %>
|
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
times << (result == result_set.first ? time.to_s : "#{time} (#{speedup}x speedup)")
end
end
template = ERB.new( TEMPLATE, 0, "%<>")
html << template.result( binding )
end
File.open( filename, 'w' ) { |file| file.write( TEMPLATE_HEADER + html ) }
end
end