Class: Benchcc::Clang
Overview
class Compiler
Instance Method Summary collapse
- #compile(file, *args) ⇒ Object
-
#initialize(binary) ⇒ Clang
constructor
A new instance of Clang.
Methods inherited from Compiler
Constructor Details
#initialize(binary) ⇒ Clang
Returns a new instance of Clang.
42 43 44 45 |
# File 'lib/benchcc/compiler.rb', line 42 def initialize(binary) @exe = `which #{binary}`.strip raise "#{binary} not found" unless $?.success? end |
Instance Method Details
#compile(file, *args) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/benchcc/compiler.rb', line 47 def compile(file, *args) file = Pathname.new(file). command = "/usr/bin/time -l #{@exe} #{args.join(' ')} -ftime-report #{file}" stdout, stderr, status = Open3.capture3(command) if status.success? memusg = stderr.match(/(\d+)\s+maximum/)[1].to_i section = -> (title) { title.gsub!(' ', '\s') /( ===-+===\n .*#{title}.*\n ===-+===\n (.|\n)+?(?====) )|( ===-+===\n .*#{title}.*\n ===-+===\n (.|\n)+ )/x } time = stderr.match(section["Miscellaneous Ungrouped Timers"]).to_s .match(/(\d+\.?\d+).+?Total/)[1] return { compilation_time: time, memory_usage: memusg } else err_string = " > \#{command}\n \#{stderr}\n\n [compiling:\n \#{file.read}\n ]\n EOS\n raise CompilationError.new(err_string)\n end\nend\n" |