Sha256: b5d7d2628e7534cb77750bf5f24fdb79dd6b08ea61283e07d504112108aff146

Contents?: true

Size: 977 Bytes

Versions: 1

Compression:

Stored size: 977 Bytes

Contents

module Benchmark
  module Plot
    class Plotter
      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

      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

      def all_labels
        @reporter.reports.keys
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
benchmark-plot-0.1 lib/benchmark/plot/plotter.rb