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
4 5 6 7 8 9 10 11 |
# 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 @test_data = test_data end |
Instance Method Details
#all_labels ⇒ Object
30 31 32 |
# File 'lib/benchmark/plot/plotter.rb', line 30 def all_labels @reporter.reports.keys end |
#plot ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/benchmark/plot/plotter.rb', line 13 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 } puts positions.zip(@test_data.map(&:to_s)).to_h plot.labels = positions.zip(@test_data.map(&:to_s)).to_h if @x_labels plot.write("#{@file_name}.png") end |