/
redundant-block-call.rb
53 lines (40 loc) · 993 Bytes
/
redundant-block-call.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# frozen_string_literal: true
# rubocop-performance
# Performance/RedundantBlockCall
# see https://github.com/rubocop-hq/rubocop-performance/blob/master/manual/cops_performance.md#performanceredundantblockcall
require 'benchmark_driver'
output = :gruff
versions = ['2.3.8', '2.4.6', '2.5.4', '2.6.3', '2.7.0-preview1']
Benchmark.driver(output: output) do |x|
x.rbenv *versions
x.prelude <<~RUBY
def bad_method(&block)
block.call
end
def bad_another(&func)
func.call 1, 2, 3
end
def good_method
yield
end
def good_another
yield 1, 2, 3
end
def bad_sample1
bad_method { 1 + 2 }
end
def bad_sample2
bad_another { |a, b, c | a + b + c }
end
def good_sample1
good_method { 1 + 2 }
end
def good_sample2
good_another { |a, b, c | a + b + c }
end
RUBY
x.report %{ bad_sample1 }
x.report %{ bad_sample2 }
x.report %{ good_sample1 }
x.report %{ good_sample2 }
end