lib/benchmark_driver/output/compare.rb in benchmark_driver-0.12.0 vs lib/benchmark_driver/output/compare.rb in benchmark_driver-0.13.0
- old
+ new
@@ -23,11 +23,11 @@
def with_benchmark(&block)
@job_context_result = Hash.new do |hash, job|
hash[job] = {}
end
- without_stdout_buffering do
+ result = without_stdout_buffering do
$stdout.puts 'Calculating -------------------------------------'
if @context_names.size > 1
$stdout.print(' ' * @name_length)
@context_names.each do |context_name|
$stdout.print(' %10s ' % context_name)
@@ -35,16 +35,16 @@
$stdout.puts
end
block.call
end
- ensure
if @context_names.size > 1
compare_executables
elsif @job_names.size > 1
compare_jobs
end
+ result
end
# @param [BenchmarkDriver::Job] job
def with_job(job, &block)
name = job.name
@@ -54,22 +54,22 @@
$stdout.print("%#{@name_length}s" % name)
end
@job = name
@job_results = []
@job_contexts = []
- block.call
- ensure
+ result = block.call
$stdout.print(@metrics.first.unit)
loop_count = @job_results.first.loop_count
if loop_count && @job_results.all? { |r| r.loop_count == loop_count }
$stdout.print(" - #{humanize(loop_count)} times")
if @job_results.all? { |result| !result.duration.nil? }
$stdout.print(" in")
show_durations
end
end
$stdout.puts
+ result
end
# @param [BenchmarkDriver::Context] context
def with_context(context, &block)
@context = context
@@ -159,30 +159,30 @@
end
def compare_jobs
$stdout.puts "\nComparison:"
results = @job_context_result.flat_map do |job, context_result|
- context_result.map { |context, result| Result.new(job: job, value: result.values.values.first, executable: context.executable) }
+ context_result.map { |context, result| Result.new(job: job, value: result.values.values.first, context: context) }
end
- show_results(results, show_executable: false)
+ show_results(results, show_context: false)
end
def compare_executables
$stdout.puts "\nComparison:"
@job_context_result.each do |job, context_result|
$stdout.puts("%#{@name_length + 2 + 11}s" % job)
results = context_result.flat_map do |context, result|
- result.values.values.map { |value| Result.new(job: job, value: value, executable: context.executable) }
+ result.values.values.map { |value| Result.new(job: job, value: value, context: context) }
end
- show_results(results, show_executable: true)
+ show_results(results, show_context: true)
end
end
# @param [Array<BenchmarkDriver::Output::Compare::Result>] results
- # @param [TrueClass,FalseClass] show_executable
- def show_results(results, show_executable:)
+ # @param [TrueClass,FalseClass] show_context
+ def show_results(results, show_context:)
results = results.sort_by do |result|
if @metrics.first.larger_better
-result.value
else
result.value
@@ -197,17 +197,17 @@
else
ratio = (result.value / first.value)
end
slower = "- %.2fx #{@metrics.first.worse_word}" % ratio
end
- if show_executable
- name = result.executable.name
+ if show_context
+ name = result.context.name
else
name = result.job
end
$stdout.puts("%#{@name_length}s: %11.1f %s #{slower}" % [name, result.value, @metrics.first.unit])
end
$stdout.puts
end
- Result = ::BenchmarkDriver::Struct.new(:job, :value, :executable)
+ Result = ::BenchmarkDriver::Struct.new(:job, :value, :context)
end