Class: Benchmark::Plot::Plotter
- Inherits:
-
Object
- Object
- Benchmark::Plot::Plotter
- Defined in:
- lib/benchmark/plot/plotter.rb
Instance Method Summary collapse
- #all_labels ⇒ Object
-
#initialize(reporter, test_data, opts) ⇒ Plotter
constructor
A new instance of Plotter.
- #plot ⇒ Object
Constructor Details
#initialize(reporter, test_data, opts) ⇒ Plotter
Returns a new instance of Plotter.
4 5 6 7 8 9 10 11 12 |
# File 'lib/benchmark/plot/plotter.rb', line 4 def initialize reporter, test_data, opts @reporter = reporter @file_name = opts[:file_name] || :benchmark_plot_graph @title = opts[:title] || :Benchmarks @time = opts[:time] || :real @x_labels = opts[:x_labels] || true @x_axis_label = opts[:x_axis_label] @test_data = test_data end |
Instance Method Details
#all_labels ⇒ Object
32 33 34 |
# File 'lib/benchmark/plot/plotter.rb', line 32 def all_labels @reporter.reports.keys end |
#plot ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/benchmark/plot/plotter.rb', line 14 def plot plot = Gruff::Line.new plot.title = @title.to_s reports = @reporter.reports reports.each do |label, report| time_data = report.map do |tms| tms.send(@time) end plot.data label, time_data end positions = Array.new(@test_data.size) { |i| i } plot.labels = positions.zip(@test_data.map(&:to_s)).to_h if @x_labels plot.x_axis_label = @x_axis_label if @x_axis_label plot.y_axis_label = 'Seconds' plot.write("#{@file_name}.png") end |