benchcc 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/benchcc/benchmark.rb +3 -3
- data/lib/benchcc/version.rb +1 -1
- data/spec/benchmark_spec.rb +28 -1
- 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: 07b5d40f9fee0b3fb681ad158ad178b59f7c3836
|
4
|
+
data.tar.gz: 5031ce36ea4b4019f516a1cc70f1a57a5f50585e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4598c095d3c2be82c288c45be30f8358bbf128e4d0ca21ec31cbbb4475ab8e58d30a1be3a04c6fe6c68c2631641eef26c88aa43abdd680db6fa9cee26a70bd27
|
7
|
+
data.tar.gz: 0b4ba5c9acf0cecf64e09d48a5b32efbe14aa54315ba223e08c23fdbe9c2729ff11e244ba3ee276b0ba9273455473fae511cecad204a122dcc9b646d12413cbc
|
data/lib/benchcc/benchmark.rb
CHANGED
@@ -28,7 +28,7 @@ module Benchcc
|
|
28
28
|
break if consecutive_errors >= 2
|
29
29
|
code = Renderer.new(relative_to).render(file, **env)
|
30
30
|
begin
|
31
|
-
Timeout::timeout(timeout) { data << env.merge(block.call(code)) }
|
31
|
+
Timeout::timeout(timeout) { data << env.merge(block.call(code).to_h) }
|
32
32
|
consecutive_errors = 0
|
33
33
|
rescue CompilationError, Timeout::Error => e
|
34
34
|
$stderr << e
|
@@ -42,9 +42,9 @@ module Benchcc
|
|
42
42
|
end
|
43
43
|
module_function :benchmark
|
44
44
|
|
45
|
-
def benchmark_to_csv(file, envs,
|
45
|
+
def benchmark_to_csv(file, envs, timeout: 10, relative_to: File.dirname(file), &block)
|
46
46
|
data = benchmark(file, envs, timeout: timeout, relative_to: relative_to, &block)
|
47
|
-
CSV.
|
47
|
+
return CSV.generate(headers: :first_row) do |csv|
|
48
48
|
csv << data.first.keys unless data.empty?
|
49
49
|
data.each { |line| csv << line.values }
|
50
50
|
end
|
data/lib/benchcc/version.rb
CHANGED
data/spec/benchmark_spec.rb
CHANGED
@@ -6,7 +6,7 @@ require 'timeout'
|
|
6
6
|
|
7
7
|
|
8
8
|
describe Benchcc.method(:benchmark) do
|
9
|
-
it('
|
9
|
+
it('should ignore timeouts') {
|
10
10
|
timeout = 0.3
|
11
11
|
envs = [{time: timeout + 0.1}, {time: timeout - 0.1},
|
12
12
|
{time: timeout + 0.2}, {time: timeout - 0.2}]
|
@@ -20,4 +20,31 @@ describe Benchcc.method(:benchmark) do
|
|
20
20
|
expect(data).to eq(envs.select { |env| env[:time] < timeout })
|
21
21
|
end
|
22
22
|
}
|
23
|
+
|
24
|
+
it('should accumulate whatever is returned from the block') {
|
25
|
+
envs = [{x: 0}, {x: 1}, {x: 2}, {x: 3}]
|
26
|
+
Tempfile.create('') do |file|
|
27
|
+
file.write('<%= x %>')
|
28
|
+
file.flush
|
29
|
+
data = Benchcc.benchmark(file.path, envs) do |x|
|
30
|
+
{x: x.to_i}
|
31
|
+
end
|
32
|
+
expect(data).to eq(envs)
|
33
|
+
end
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
describe Benchcc.method(:benchmark_to_csv) do
|
38
|
+
it('should output to csv correctly') {
|
39
|
+
envs = [{x: 1, y:-1}, {x: 2, y:-2}, {x: 3, y:-3}]
|
40
|
+
Tempfile.create('') do |file|
|
41
|
+
file.write('<%= x %> <%= y %>')
|
42
|
+
file.flush
|
43
|
+
csv = Benchcc.benchmark_to_csv(file.path, envs) do |str|
|
44
|
+
x, y = str.split(' ')
|
45
|
+
{x: x.to_i, y: y.to_i}
|
46
|
+
end
|
47
|
+
expect(csv).to eq("x,y\n1,-1\n2,-2\n3,-3\n")
|
48
|
+
end
|
49
|
+
}
|
23
50
|
end
|