Module: Benchcc

Defined in:
lib/benchcc/mpl.rb,
lib/benchcc/plot.rb,
lib/benchcc/fusion.rb,
lib/benchcc/version.rb,
lib/benchcc/compiler.rb,
lib/benchcc/benchmark.rb

Defined Under Namespace

Modules: Fusion, MPL Classes: Clang, CompilationError, Compiler, GCC, Renderer

Constant Summary collapse

Y_FEATURES =
[:memory_usage, :compilation_time, :run_time]
DEFAULT_TWEAK =

How do I make this private?

{
  memory_usage: -> (plot) {
    plot.ylabel   'Memory usage'
    plot.decimal  'locale \'en_US.UTF-8\''
    plot.format   'y \'%.2e kb\''
  },

  compilation_time: -> (plot) {
    plot.ylabel   'Compilation time'
    plot.format   'y \'%.2g s\''
  },

  run_time: -> (plot) {
    plot.ylabel   'Run time'
    plot.format   'y \'%.2g s\''
  }
}
VERSION =
"0.0.8"

Class Method Summary collapse

Class Method Details

.benchmark(erb_file, environments, timeout: 10, evaluate_erb_relative_to: File.dirname(erb_file), &bench) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/benchcc/benchmark.rb', line 23

def benchmark(erb_file, environments, timeout: 10,
              evaluate_erb_relative_to: File.dirname(erb_file), &bench)
  erb_file = Pathname.new(erb_file)
  progress = ProgressBar.create(format: '%p%% | %B |', total: environments.size)

  data = CSV.generate({headers: :first_row}) do |csv|
    csv << [:input_size, :compilation_time, :memory_usage, :run_time]

    environments.each do |env|
      code = Renderer.new(evaluate_erb_relative_to).render(erb_file, **env)
      begin
        Tempfile.create([erb_file.basename, '.cpp']) do |tmp|
          tmp.write(code) && tmp.close
          bench_data = Timeout::timeout(timeout) {
            bench.call(tmp.path, env)
          }
          row = {
            input_size: env[:input_size],
            compilation_time: bench_data[:compilation_time],
            memory_usage: bench_data[:memory_usage],
            run_time: bench_data[:run_time] # TODO: implement this
          }
          csv << row
        end
      rescue CompilationError, Timeout::Error => e
        $stderr << e
        break
      end
      progress.increment
    end
  end
  return data
ensure
  progress.finish
end

.plot(output, titles, inputs, x_feature: :input_size, y_feature: :compilation_time, &tweak) ⇒ Object

Raises:

  • (ArgumentError)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/benchcc/plot.rb', line 27

def plot(output, titles, inputs, x_feature: :input_size, y_feature: :compilation_time, &tweak)
  raise ArgumentError if not Benchcc::Y_FEATURES.include?(y_feature)
  tweak ||= Benchcc::DEFAULT_TWEAK[y_feature]

  Gnuplot.open do |io|
    Gnuplot::Plot.new(io) do |plot|
      plot.term     'png'
      plot.output   output
      plot.data = titles.zip(inputs).map { |title, file|
        csv = CSV.table(file)
        Gnuplot::DataSet.new([csv[x_feature], csv[y_feature]]) { |ds|
          ds.title = title
          ds.with = 'lines'
        }
      }
      tweak.call(plot)
    end
  end
end