radius-spec 0.7.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,285 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Data values are taken from the Rubocop Style/HashLikeCase example
4
+ #
5
+ # https://docs.rubocop.org/rubocop/1.21/cops_style.html#styleredundantfileextensioninrequire
6
+
7
+ # Run from the command line: bundle exec ruby benchmarks/style_hash_like_case.rb
8
+ require_relative 'bm_setup'
9
+
10
+ display_benchmark_header
11
+
12
+ # rubocop:disable Style/HashLikeCase
13
+ def case_check3(value)
14
+ case value
15
+ when 'europe'
16
+ 'http://eu.example.com'
17
+ when 'america'
18
+ 'http://us.example.com'
19
+ when 'australia'
20
+ 'http://au.example.com'
21
+ end
22
+ end
23
+
24
+ HASH_CASE3 = {
25
+ 'europe' => 'http://eu.example.com',
26
+ 'america' => 'http://us.example.com',
27
+ 'australia' => 'http://au.example.com',
28
+ }.freeze
29
+
30
+ def hash_check3(value)
31
+ HASH_CASE3[value]
32
+ end
33
+
34
+ section "Style/HashLikeCase(3) - First Match" do |bench|
35
+ bench.report("case") do |times|
36
+ i = 0
37
+ while i < times
38
+ case_check3('europe')
39
+ i += 1
40
+ end
41
+ end
42
+
43
+ bench.report("hash") do |times|
44
+ i = 0
45
+ while i < times
46
+ hash_check3('europe')
47
+ i += 1
48
+ end
49
+ end
50
+ end
51
+
52
+ section "Style/HashLikeCase(3) - Last Match" do |bench|
53
+ bench.report("case") do |times|
54
+ i = 0
55
+ while i < times
56
+ case_check3('australia')
57
+ i += 1
58
+ end
59
+ end
60
+
61
+ bench.report("hash") do |times|
62
+ i = 0
63
+ while i < times
64
+ hash_check3('australia')
65
+ i += 1
66
+ end
67
+ end
68
+ end
69
+
70
+ section "Style/HashLikeCase(3) - No Match" do |bench|
71
+ bench.report("case") do |times|
72
+ i = 0
73
+ while i < times
74
+ case_check3('any other place')
75
+ i += 1
76
+ end
77
+ end
78
+
79
+ bench.report("hash") do |times|
80
+ i = 0
81
+ while i < times
82
+ hash_check3('any other place')
83
+ i += 1
84
+ end
85
+ end
86
+ end
87
+
88
+ def case_check5(value) # rubocop:disable Metrics/MethodLength
89
+ case value
90
+ when 'europe'
91
+ 'http://eu.example.com'
92
+ when 'america'
93
+ 'http://us.example.com'
94
+ when 'australia'
95
+ 'http://au.example.com'
96
+ when 'china'
97
+ 'http://cn.example.com'
98
+ when 'japan'
99
+ 'http://jp.example.com'
100
+ end
101
+ end
102
+
103
+ HASH_CASE5 = {
104
+ 'europe' => 'http://eu.example.com',
105
+ 'america' => 'http://us.example.com',
106
+ 'australia' => 'http://au.example.com',
107
+ 'china' => 'http://cn.example.com',
108
+ 'japan' => 'http://jp.example.com',
109
+ }.freeze
110
+
111
+ def hash_check5(value)
112
+ HASH_CASE5[value]
113
+ end
114
+
115
+ section "Style/HashLikeCase(5) - First Match" do |bench|
116
+ bench.report("case") do |times|
117
+ i = 0
118
+ while i < times
119
+ case_check5('europe')
120
+ i += 1
121
+ end
122
+ end
123
+
124
+ bench.report("hash") do |times|
125
+ i = 0
126
+ while i < times
127
+ hash_check5('europe')
128
+ i += 1
129
+ end
130
+ end
131
+ end
132
+
133
+ section "Style/HashLikeCase(5) - Last Match" do |bench|
134
+ bench.report("case") do |times|
135
+ i = 0
136
+ while i < times
137
+ case_check5('japan')
138
+ i += 1
139
+ end
140
+ end
141
+
142
+ bench.report("hash") do |times|
143
+ i = 0
144
+ while i < times
145
+ hash_check5('japan')
146
+ i += 1
147
+ end
148
+ end
149
+ end
150
+
151
+ section "Style/HashLikeCase(5) - No Match" do |bench|
152
+ bench.report("case") do |times|
153
+ i = 0
154
+ while i < times
155
+ case_check5('any other place')
156
+ i += 1
157
+ end
158
+ end
159
+
160
+ bench.report("hash") do |times|
161
+ i = 0
162
+ while i < times
163
+ hash_check5('any other place')
164
+ i += 1
165
+ end
166
+ end
167
+ end
168
+
169
+ # rubocop:enable Style/HashLikeCase
170
+
171
+ __END__
172
+
173
+ Usage of `case` appears to be more performant than a hash. However, both are
174
+ highly performant, so any difference is likely negligible compared to other
175
+ performance issues.
176
+
177
+ ### Environment
178
+
179
+ Performance-M Dyno
180
+ ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [x86_64-linux]
181
+ GC Disabled: true
182
+
183
+ ### Test Cases
184
+
185
+ #### Style/HashLikeCase(3) - First Match
186
+
187
+ ```
188
+ Warming up --------------------------------------
189
+ case 1.768M i/100ms
190
+ hash 1.710M i/100ms
191
+ Calculating -------------------------------------
192
+ case 17.630M (± 0.3%) i/s - 88.418M in 5.016811s
193
+ hash 17.044M (± 0.2%) i/s - 85.504M in 5.017564s
194
+ with 95.0% confidence
195
+
196
+ Comparison:
197
+ case: 17630438.8 i/s
198
+ hash: 17044158.0 i/s - 1.03x (± 0.00) slower
199
+ with 95.0% confidence
200
+ ```
201
+
202
+ #### Style/HashLikeCase(3) - Last Match
203
+
204
+ ```
205
+ Warming up --------------------------------------
206
+ case 1.714M i/100ms
207
+ hash 1.644M i/100ms
208
+ Calculating -------------------------------------
209
+ case 17.066M (± 0.7%) i/s - 85.718M in 5.027638s
210
+ hash 16.432M (± 0.1%) i/s - 82.205M in 5.002925s
211
+ with 95.0% confidence
212
+
213
+ Comparison:
214
+ case: 17066448.1 i/s
215
+ hash: 16432193.1 i/s - 1.04x (± 0.01) slower
216
+ with 95.0% confidence
217
+ ```
218
+
219
+ #### Style/HashLikeCase(3) - No Match
220
+
221
+ ```
222
+ Warming up --------------------------------------
223
+ case 1.706M i/100ms
224
+ hash 1.529M i/100ms
225
+ Calculating -------------------------------------
226
+ case 16.944M (± 0.8%) i/s - 85.300M in 5.041700s
227
+ hash 15.210M (± 0.5%) i/s - 76.428M in 5.028693s
228
+ with 95.0% confidence
229
+
230
+ Comparison:
231
+ case: 16944279.7 i/s
232
+ hash: 15210481.2 i/s - 1.11x (± 0.01) slower
233
+ with 95.0% confidence
234
+ ```
235
+
236
+ #### Style/HashLikeCase(5) - First Match
237
+
238
+ ```
239
+ Warming up --------------------------------------
240
+ case 1.738M i/100ms
241
+ hash 1.704M i/100ms
242
+ Calculating -------------------------------------
243
+ case 17.621M (± 0.5%) i/s - 88.642M in 5.033716s
244
+ hash 16.963M (± 0.5%) i/s - 85.198M in 5.025691s
245
+ with 95.0% confidence
246
+
247
+ Comparison:
248
+ case: 17621070.3 i/s
249
+ hash: 16963331.9 i/s - 1.04x (± 0.01) slower
250
+ with 95.0% confidence
251
+ ```
252
+
253
+ #### Style/HashLikeCase(5) - Last Match
254
+
255
+ ```
256
+ Warming up --------------------------------------
257
+ case 1.718M i/100ms
258
+ hash 1.634M i/100ms
259
+ Calculating -------------------------------------
260
+ case 17.170M (± 0.0%) i/s - 85.898M in 5.002845s
261
+ hash 16.357M (± 0.3%) i/s - 83.338M in 5.097011s
262
+ with 95.0% confidence
263
+
264
+ Comparison:
265
+ case: 17170019.6 i/s
266
+ hash: 16356675.5 i/s - 1.05x (± 0.00) slower
267
+ with 95.0% confidence
268
+ ```
269
+
270
+ #### Style/HashLikeCase(5) - No Match
271
+
272
+ ```
273
+ Warming up --------------------------------------
274
+ case 1.661M i/100ms
275
+ hash 1.501M i/100ms
276
+ Calculating -------------------------------------
277
+ case 16.518M (± 0.6%) i/s - 83.046M in 5.031835s
278
+ hash 14.963M (± 0.5%) i/s - 75.058M in 5.019838s
279
+ with 95.0% confidence
280
+
281
+ Comparison:
282
+ case: 16517985.2 i/s
283
+ hash: 14962803.1 i/s - 1.10x (± 0.01) slower
284
+ with 95.0% confidence
285
+ ```
@@ -5,7 +5,6 @@ require_relative 'bm_setup'
5
5
 
6
6
  display_benchmark_header
7
7
 
8
- # rubocop:disable Performance/UnfreezeString
9
8
  section "Unfreezing empty string" do |bench|
10
9
  bench.report("String.new") do
11
10
  String.new
@@ -34,7 +33,6 @@ section "Unfreezing string" do |bench|
34
33
  STRING.dup
35
34
  end
36
35
  end
37
- # rubocop:enable Performance/UnfreezeString
38
36
 
39
37
  __END__
40
38
 
data/bin/bundle ADDED
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'bundle' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "rubygems"
12
+
13
+ m = Module.new do
14
+ module_function
15
+
16
+ def invoked_as_script?
17
+ File.expand_path($0) == File.expand_path(__FILE__)
18
+ end
19
+
20
+ def env_var_version
21
+ ENV["BUNDLER_VERSION"]
22
+ end
23
+
24
+ def cli_arg_version
25
+ return unless invoked_as_script? # don't want to hijack other binstubs
26
+ return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
27
+ bundler_version = nil
28
+ update_index = nil
29
+ ARGV.each_with_index do |a, i|
30
+ if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
31
+ bundler_version = a
32
+ end
33
+ next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
34
+ bundler_version = $1
35
+ update_index = i
36
+ end
37
+ bundler_version
38
+ end
39
+
40
+ def gemfile
41
+ gemfile = ENV["BUNDLE_GEMFILE"]
42
+ return gemfile if gemfile && !gemfile.empty?
43
+
44
+ File.expand_path("../../Gemfile", __FILE__)
45
+ end
46
+
47
+ def lockfile
48
+ lockfile =
49
+ case File.basename(gemfile)
50
+ when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
51
+ else "#{gemfile}.lock"
52
+ end
53
+ File.expand_path(lockfile)
54
+ end
55
+
56
+ def lockfile_version
57
+ return unless File.file?(lockfile)
58
+ lockfile_contents = File.read(lockfile)
59
+ return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
60
+ Regexp.last_match(1)
61
+ end
62
+
63
+ def bundler_version
64
+ @bundler_version ||=
65
+ env_var_version || cli_arg_version ||
66
+ lockfile_version
67
+ end
68
+
69
+ def bundler_requirement
70
+ return "#{Gem::Requirement.default}.a" unless bundler_version
71
+
72
+ bundler_gem_version = Gem::Version.new(bundler_version)
73
+
74
+ requirement = bundler_gem_version.approximate_recommendation
75
+
76
+ return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0")
77
+
78
+ requirement += ".a" if bundler_gem_version.prerelease?
79
+
80
+ requirement
81
+ end
82
+
83
+ def load_bundler!
84
+ ENV["BUNDLE_GEMFILE"] ||= gemfile
85
+
86
+ activate_bundler
87
+ end
88
+
89
+ def activate_bundler
90
+ gem_error = activation_error_handling do
91
+ gem "bundler", bundler_requirement
92
+ end
93
+ return if gem_error.nil?
94
+ require_error = activation_error_handling do
95
+ require "bundler/version"
96
+ end
97
+ return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
98
+ warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
99
+ exit 42
100
+ end
101
+
102
+ def activation_error_handling
103
+ yield
104
+ nil
105
+ rescue StandardError, LoadError => e
106
+ e
107
+ end
108
+ end
109
+
110
+ m.load_bundler!
111
+
112
+ if m.invoked_as_script?
113
+ load Gem.bin_path("bundler", "bundle")
114
+ end