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 +4 -4
- data/lib/benchcc/compiler.rb +53 -26
- data/lib/benchcc/version.rb +1 -1
- data/spec/compiler_spec.rb +1 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f076faa51fa97fb6499def81a757dd5f638ff415
|
4
|
+
data.tar.gz: 1c981a344f64ef8d2e38985073886b688564f9cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3664e71641c0d756424e76ca3f3a62c35888de6ab305ab6513f21891b9b1eb2947d78e6693ea0717d5e9e53a0971475a0d782bcebb9a16eaba1f08fa137e9288
|
7
|
+
data.tar.gz: aa2be5121dc575c61967e779b62a07e402ec1f9e73df108c68acfbf9a78f4272d09c0fe294cda0db312fddf5eccc29a8b67e0de2ff7520d4d4fa3da45021a935
|
data/lib/benchcc/compiler.rb
CHANGED
@@ -5,23 +5,40 @@ require 'tempfile'
|
|
5
5
|
|
6
6
|
module Benchcc
|
7
7
|
class CompilationError < RuntimeError
|
8
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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 ->
|
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 ->
|
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
|
-
|
90
|
-
|
91
|
-
|
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
|
-
|
112
|
-
|
113
|
-
|
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
|
data/lib/benchcc/version.rb
CHANGED
data/spec/compiler_spec.rb
CHANGED
@@ -60,9 +60,7 @@ end
|
|
60
60
|
}
|
61
61
|
|
62
62
|
it('returns statistics on valid input') {
|
63
|
-
|
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
|