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, CompilationResult, Compiler, GCC, Renderer
Constant Summary
collapse
- VERSION =
"0.0.2"
Class Method Summary
collapse
-
.benchmark(file, envs, timeout: 10, relative_to: File.dirname(file), &block) ⇒ Object
-
.benchmark_to_csv(file, envs, out, timeout: 10, relative_to: File.dirname(file), &block) ⇒ Object
-
.plot_memusg(output, *inputs) ⇒ Object
-
.plot_time(output, *inputs) ⇒ Object
Class Method Details
.benchmark(file, envs, timeout: 10, relative_to: File.dirname(file), &block) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/benchcc/benchmark.rb', line 23
def benchmark(file, envs, timeout: 10, relative_to: File.dirname(file), &block)
progress = ProgressBar.create(format: "#{file} %p%% | %B |",
total: envs.size)
consecutive_errors, data = 0, []
envs.each do |env|
break if consecutive_errors >= 2
code = Renderer.new(relative_to).render(file, **env)
begin
Timeout::timeout(timeout) { data << env.merge(block.call(code)) }
consecutive_errors = 0
rescue CompilationError, Timeout::Error => e
$stderr << e
consecutive_errors += 1
end
progress.increment
end
return data
ensure
progress.finish
end
|
.benchmark_to_csv(file, envs, out, timeout: 10, relative_to: File.dirname(file), &block) ⇒ Object
45
46
47
48
49
50
51
|
# File 'lib/benchcc/benchmark.rb', line 45
def benchmark_to_csv(file, envs, out, timeout: 10, relative_to: File.dirname(file), &block)
data = benchmark(file, envs, timeout: timeout, relative_to: relative_to, &block)
CSV.open(out, 'wb') do |csv|
csv << data.first.keys unless data.empty?
data.each { |line| csv << line.values }
end
end
|
.plot_memusg(output, *inputs) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/benchcc/plot.rb', line 6
def plot_memusg(output, *inputs)
Gnuplot.open do |io|
Gnuplot::Plot.new(io) do |plot|
plot.ylabel 'Memory usage'
plot.decimal "locale 'en_US.UTF-8'"
plot.format 'y "%.2e kb"'
plot.term 'png'
plot.output output
plot.data = inputs.map { |file|
csv = CSV.table(file)
Gnuplot::DataSet.new([csv[:x], csv[:peak_memusg]]) { |ds|
ds.title = file
ds.with = 'lines'
}
}
end
end
end
|
.plot_time(output, *inputs) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/benchcc/plot.rb', line 26
def plot_time(output, *inputs)
Gnuplot.open do |io|
Gnuplot::Plot.new(io) do |plot|
plot.ylabel 'Compilation time'
plot.format 'y "%.2g s"'
plot.term 'png'
plot.output output
plot.data = inputs.map { |file|
csv = CSV.table(file)
Gnuplot::DataSet.new([csv[:x], csv[:wall_time]]) { |ds|
ds.title = file
ds.with = 'lines'
}
}
end
end
end
|