Class: Benchcc::GCC
Instance Method Summary collapse
- #compile(file, *args) ⇒ Object
-
#initialize(binary) ⇒ GCC
constructor
A new instance of GCC.
Methods inherited from Compiler
Constructor Details
#initialize(binary) ⇒ GCC
Returns a new instance of GCC.
93 94 95 96 |
# File 'lib/benchcc/compiler.rb', line 93 def initialize(binary) @exe = `which #{binary}`.strip raise "#{binary} not found" unless $?.success? end |
Instance Method Details
#compile(file, *args) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/benchcc/compiler.rb', line 98 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? time = stderr.match(/TOTAL.+/).to_s.split[-3].to_f memusg = stderr.match(/(\d+)\s+maximum/)[1].to_i 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".strip_heredoc |