class Benchmark::BigO::TermPlot

Public Class Methods

new(report_data, sizes) click to toggle source
# File lib/benchmark/bigo/termplot.rb, line 5
def initialize report_data, sizes
  @data = report_data
  @sizes = sizes
  @dat_file = Tempfile.new 'termplot'
end

Public Instance Methods

commands() click to toggle source
# File lib/benchmark/bigo/termplot.rb, line 44
def commands

  cmds = []
  cmds << "set term dumb"
  cmds << "set key top left vertical inside width 3"

  data_idx = 0

  while data_idx < @data.length

    if data_idx == 0
      str = "plot '#{@dat_file.path}'"
    else
      str = "\"\""
    end

    str += " using 1:#{data_idx+2} title '#{title_for(data_idx)}' with lines"
    str += ",\\" unless data_idx == @data.length-1

    cmds << str

    data_idx += 1
  end

  cmds
end
dat_lines() click to toggle source
# File lib/benchmark/bigo/termplot.rb, line 31
def dat_lines
  lines = []
  @sizes.each do |size|
    line = [size] + @data.collect{|d| d[:data][size] }
    lines << line.join('   ')
  end
  lines
end
generate() click to toggle source
# File lib/benchmark/bigo/termplot.rb, line 11
def generate

  write_dat_file

  begin
    IO.popen("gnuplot", "w") { |io| io.puts commands }
  rescue
    puts "You need to have gnuplot installed!"
    puts "brew install gnuplot"
  end
end
title_for(index) click to toggle source
# File lib/benchmark/bigo/termplot.rb, line 40
def title_for index
  @data[index][:name]
end
write_dat_file() click to toggle source
# File lib/benchmark/bigo/termplot.rb, line 23
def write_dat_file
  File.open(@dat_file.path, 'w') do |file|
    dat_lines.each do |line|
      file.puts line
    end
  end
end