benchcc 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c435cda71ad508017a69a33b232ef6a7ed334df8
4
- data.tar.gz: c2c9a7bd9355414ea1388f7e792b630a3a0b79c8
3
+ metadata.gz: f076faa51fa97fb6499def81a757dd5f638ff415
4
+ data.tar.gz: 1c981a344f64ef8d2e38985073886b688564f9cd
5
5
  SHA512:
6
- metadata.gz: da5d488a8e4cdb1984cb174c6b622dcba891d588bd734c9421f02dd6c412d1c243b307b09b0f4c3fba7476342a9acbfb520818abdbe80714dbebac666e9a4812
7
- data.tar.gz: c5ab9643575c8d740e5521e8ed8ad04d78751488a30773b951a4bdb57a0fbf1319d75c4e3d3c4b6734f67647b2f394abd1ec9716907b9ebe3081479dc67a48aa
6
+ metadata.gz: 3664e71641c0d756424e76ca3f3a62c35888de6ab305ab6513f21891b9b1eb2947d78e6693ea0717d5e9e53a0971475a0d782bcebb9a16eaba1f08fa137e9288
7
+ data.tar.gz: aa2be5121dc575c61967e779b62a07e402ec1f9e73df108c68acfbf9a78f4272d09c0fe294cda0db312fddf5eccc29a8b67e0de2ff7520d4d4fa3da45021a935
@@ -5,23 +5,40 @@ require 'tempfile'
5
5
 
6
6
  module Benchcc
7
7
  class CompilationError < RuntimeError
8
- def initialize(command_line, code, compiler_error_message)
9
- @cli = command_line
10
- @code = code
11
- @compiler_stderr = compiler_error_message
12
- end
8
+ end
13
9
 
10
+ # Structure holding various information about the compilation of a file.
11
+ CompilationResult = Struct.new('CompilationResult',
12
+ # The time taken to compile.
13
+ :wall_time,
14
+ # The peak memory usage during compilation.
15
+ :peak_memusg,
16
+ # The standard error produced during compilation.
17
+ :stderr,
18
+ # The standard output produced during compilation.
19
+ :stdout,
20
+ # The input source that was compiled.
21
+ :code,
22
+ # The command line used for compilation.
23
+ :command_line
24
+ ) do
14
25
  def to_s
15
26
  <<-EOS
16
- compilation failed when invoking "#{@cli}"
17
- compiler error message was:
18
- #{'-' * 80}
19
- #{@compiler_stderr}
20
-
21
- full compiled file was:
22
- #{'-' * 80}
23
- #{@code}
24
- EOS
27
+ command line: #{command_line}
28
+ compilation time: #{wall_time}
29
+ peak memory usage: #{peak_memusg}
30
+ #{'=' * 30} [begin code] #{'=' * 30}
31
+ #{code}
32
+ #{'=' * 30} [end code] #{'=' * 30}
33
+
34
+ #{'=' * 30} [begin stdout] #{'=' * 30}
35
+ #{stdout}
36
+ #{'=' * 30} [end stdout] #{'=' * 30}
37
+
38
+ #{'=' * 30} [begin stderr] #{'=' * 30}
39
+ #{stderr}
40
+ #{'=' * 30} [end stderr] #{'=' * 30}
41
+ EOS
25
42
  end
26
43
  end
27
44
 
@@ -42,7 +59,7 @@ module Benchcc
42
59
  raise NotImplementedError
43
60
  end
44
61
 
45
- # compile_file: Path -> Hash
62
+ # compile_file: Path -> CompilationResult
46
63
  #
47
64
  # Compile the given file and return compilation statistics.
48
65
  #
@@ -57,7 +74,7 @@ module Benchcc
57
74
  compile_code(code, *args)
58
75
  end
59
76
 
60
- # compile_code: String -> Hash
77
+ # compile_code: String -> CompilationResult
61
78
  #
62
79
  # Compile the given string and return compilation statistics.
63
80
  #
@@ -84,12 +101,17 @@ module Benchcc
84
101
  file = Pathname.new(file).expand_path
85
102
  command = "time -l #{@exe} #{args.join(' ')} -ftime-report #{file}"
86
103
  stdout, stderr, status = Open3.capture3(command)
87
- raise CompilationError.new(command, file.read, stderr) unless status.success?
88
104
 
89
- return {
90
- peak_memusg: stderr.match(/(\d+)\s+maximum/)[1].to_i,
91
- wall_time: stderr.match(/.+Total/).to_s.split[-3].to_f
92
- }
105
+ result = CompilationResult.new
106
+ result.stderr = stderr
107
+ result.stdout = stdout
108
+ result.code = file.read
109
+ result.command_line = command
110
+ raise CompilationError.new(result) unless status.success?
111
+
112
+ result.peak_memusg = stderr.match(/(\d+)\s+maximum/)[1].to_i
113
+ result.wall_time = stderr.match(/.+Total/).to_s.split[-3].to_f
114
+ return result
93
115
  end
94
116
 
95
117
  def template_depth; 256; end
@@ -106,12 +128,17 @@ module Benchcc
106
128
  file = Pathname.new(file).expand_path
107
129
  command = "time -l #{@exe} #{args.join(' ')} -ftime-report #{file}"
108
130
  stdout, stderr, status = Open3.capture3(command)
109
- raise CompilationError.new(command, file.read, stderr) unless status.success?
110
131
 
111
- return {
112
- peak_memusg: stderr.match(/(\d+)\s+maximum/)[1].to_i,
113
- wall_time: stderr.match(/TOTAL.+/).to_s.split[-3].to_f
114
- }
132
+ result = CompilationResult.new
133
+ result.stderr = stderr
134
+ result.stdout = stdout
135
+ result.code = file.read
136
+ result.command_line = command
137
+ raise CompilationError.new(result) unless status.success?
138
+
139
+ result.peak_memusg = stderr.match(/(\d+)\s+maximum/)[1].to_i
140
+ result.wall_time = stderr.match(/TOTAL.+/).to_s.split[-3].to_f
141
+ return result
115
142
  end
116
143
 
117
144
  def template_depth; 900; end
@@ -1,3 +1,3 @@
1
1
  module Benchcc
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -60,9 +60,7 @@ end
60
60
  }
61
61
 
62
62
  it('returns statistics on valid input') {
63
- result = @cc.compile_file(@valid, '-o /dev/null')
64
- expect(result).to have_key(:peak_memusg)
65
- expect(result).to have_key(:wall_time)
63
+ expect(@cc.compile_file(@valid, '-o /dev/null')).to be_instance_of(Benchcc::CompilationResult)
66
64
  }
67
65
  end
68
66
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: benchcc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Louis Dionne