radius-spec 0.2.0 → 0.6.0

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.
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Run from the command line: bundle exec ruby benchmarks/cover_vs_include.rb
4
+ require_relative 'bm_setup'
5
+
6
+ display_benchmark_header
7
+
8
+ INT_RANGE = (0..15)
9
+ INT_VAR = 10
10
+
11
+ section "Integer ranges" do |bench|
12
+ bench.report('range#cover?') do
13
+ INT_RANGE.cover?(INT_VAR)
14
+ end
15
+
16
+ bench.report('range#include?') do
17
+ INT_RANGE.include?(INT_VAR)
18
+ end
19
+
20
+ bench.report('range#member?') do
21
+ INT_RANGE.member?(INT_VAR)
22
+ end
23
+
24
+ bench.report('plain compare') do
25
+ 0 < INT_VAR && INT_VAR < 15
26
+ end
27
+ end
28
+
29
+ BEGIN_OF_JULY = Time.utc(2015, 7, 1)
30
+ END_OF_JULY = Time.utc(2015, 7, 31)
31
+ DAY_IN_JULY = Time.utc(2015, 7, 15)
32
+
33
+ TIME_RANGE = (BEGIN_OF_JULY..END_OF_JULY)
34
+
35
+ section "Time ranges" do |bench|
36
+ bench.report('range#cover?') do
37
+ TIME_RANGE.cover?(DAY_IN_JULY)
38
+ end
39
+
40
+ bench.report('range#include?') do
41
+ TIME_RANGE.include?(DAY_IN_JULY)
42
+ end
43
+
44
+ bench.report('range#member?') do
45
+ TIME_RANGE.member?(DAY_IN_JULY)
46
+ end
47
+
48
+ bench.report('plain compare') do
49
+ BEGIN_OF_JULY < DAY_IN_JULY && DAY_IN_JULY < END_OF_JULY
50
+ end
51
+ end
52
+
53
+ __END__
54
+
55
+ ### Environment
56
+
57
+ ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin16]
58
+ GC Disabled: false
59
+
60
+ ### Test Cases
61
+
62
+ #### Integer ranges
63
+
64
+ ```
65
+ Warming up --------------------------------------
66
+ range#cover? 247.959k i/100ms
67
+ range#include? 251.846k i/100ms
68
+ range#member? 251.416k i/100ms
69
+ plain compare 305.858k i/100ms
70
+ Calculating -------------------------------------
71
+ range#cover? 6.400M (± 0.8%) i/s - 31.987M in 5.008881s
72
+ range#include? 6.328M (± 0.8%) i/s - 31.733M in 5.025377s
73
+ range#member? 6.366M (± 0.6%) i/s - 31.930M in 5.022146s
74
+ plain compare 11.042M (± 0.8%) i/s - 55.054M in 4.999666s
75
+ with 95.0% confidence
76
+
77
+ Comparison:
78
+ plain compare: 11041684.3 i/s
79
+ range#cover?: 6399832.9 i/s - 1.73x (± 0.02) slower
80
+ range#member?: 6366323.6 i/s - 1.73x (± 0.02) slower
81
+ range#include?: 6327682.0 i/s - 1.75x (± 0.02) slower
82
+ with 95.0% confidence
83
+ ```
84
+
85
+ #### Time ranges
86
+
87
+ ```
88
+ Warming up --------------------------------------
89
+ range#cover? 249.380k i/100ms
90
+ range#include? 247.775k i/100ms
91
+ range#member? 247.446k i/100ms
92
+ plain compare 223.517k i/100ms
93
+ Calculating -------------------------------------
94
+ range#cover? 5.942M (± 0.7%) i/s - 29.676M in 5.002164s
95
+ range#include? 5.724M (± 0.7%) i/s - 28.742M in 5.028509s
96
+ range#member? 5.771M (± 0.7%) i/s - 28.951M in 5.024809s
97
+ plain compare 4.751M (± 0.9%) i/s - 23.916M in 5.046978s
98
+ with 95.0% confidence
99
+
100
+ Comparison:
101
+ range#cover?: 5941582.8 i/s
102
+ range#member?: 5770708.7 i/s - 1.03x (± 0.01) slower
103
+ range#include?: 5723795.5 i/s - 1.04x (± 0.01) slower
104
+ plain compare: 4750545.5 i/s - 1.25x (± 0.01) slower
105
+ with 95.0% confidence
106
+ ```
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Run from the command line: bundle exec ruby benchmarks/delete_vs_tr.rb
4
+ require_relative 'bm_setup'
5
+
6
+ display_benchmark_header
7
+
8
+ [
9
+ ["No Removal", "Any String Chars", "m", ""],
10
+ ["Single Removal", "Any String Chars", "i", ""],
11
+ ["Multiple Removal", "Any String Chars", "n", ""],
12
+ ["Multi-Char Removal", "Any String Chars", "nar", ""],
13
+ ].each do |title, str, pattern, replacement|
14
+ section title do |bench|
15
+ bench.report("delete") do
16
+ str.delete(pattern)
17
+ end
18
+
19
+ bench.report("tr") do
20
+ str.tr(pattern, replacement)
21
+ end
22
+ end
23
+ end
24
+
25
+ __END__
26
+
27
+ ### Environment
28
+
29
+ ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin16]
30
+ GC Disabled: false
31
+
32
+ ### Test Cases
33
+
34
+ #### No Removal
35
+
36
+ ```
37
+ Warming up --------------------------------------
38
+ delete 164.989k i/100ms
39
+ tr 163.504k i/100ms
40
+ Calculating -------------------------------------
41
+ delete 2.578M (± 0.9%) i/s - 13.034M in 5.065099s
42
+ tr 2.566M (± 0.8%) i/s - 12.917M in 5.039546s
43
+ with 95.0% confidence
44
+
45
+ Comparison:
46
+ delete: 2578043.5 i/s
47
+ tr: 2565794.9 i/s - same-ish: difference falls within error
48
+ with 95.0% confidence
49
+ ```
50
+
51
+ #### Single Removal
52
+
53
+ ```
54
+ Warming up --------------------------------------
55
+ delete 169.321k i/100ms
56
+ tr 173.594k i/100ms
57
+ Calculating -------------------------------------
58
+ delete 2.779M (± 1.1%) i/s - 13.884M in 5.010559s
59
+ tr 2.721M (± 1.0%) i/s - 13.714M in 5.050566s
60
+ with 95.0% confidence
61
+
62
+ Comparison:
63
+ delete: 2778762.2 i/s
64
+ tr: 2721121.1 i/s - 1.02x (± 0.02) slower
65
+ with 95.0% confidence
66
+ ```
67
+
68
+ #### Multiple Removal
69
+
70
+ ```
71
+ Warming up --------------------------------------
72
+ delete 173.074k i/100ms
73
+ tr 171.824k i/100ms
74
+ Calculating -------------------------------------
75
+ delete 2.804M (± 1.0%) i/s - 14.019M in 5.009616s
76
+ tr 2.739M (± 1.0%) i/s - 13.746M in 5.030533s
77
+ with 95.0% confidence
78
+
79
+ Comparison:
80
+ delete: 2804348.9 i/s
81
+ tr: 2739399.1 i/s - 1.02x (± 0.01) slower
82
+ with 95.0% confidence
83
+ ```
84
+
85
+ #### Multi-Char Removal
86
+
87
+ ```
88
+ Warming up --------------------------------------
89
+ delete 165.485k i/100ms
90
+ tr 158.961k i/100ms
91
+ Calculating -------------------------------------
92
+ delete 2.547M (± 1.3%) i/s - 12.742M in 5.019971s
93
+ tr 2.507M (± 1.0%) i/s - 12.558M in 5.018688s
94
+ with 95.0% confidence
95
+
96
+ Comparison:
97
+ delete: 2547442.6 i/s
98
+ tr: 2507427.2 i/s - same-ish: difference falls within error
99
+ with 95.0% confidence
100
+ ```
@@ -0,0 +1,167 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Run from the command line: bundle exec ruby benchmarks/double_negation.rb
4
+ require_relative 'bm_setup'
5
+ require 'active_support'
6
+ require 'active_support/core_ext/object/blank'
7
+
8
+ display_benchmark_header
9
+
10
+ # rubocop:disable Style/NonNilCheck
11
+ # As this is basically a micro-benchmark we use the block with `while` idiom
12
+ [nil, [], Object.new].each do |x|
13
+ section x.inspect do |bench|
14
+ bench.report("!!") do |times|
15
+ i = 0
16
+ while i < times
17
+ !!x
18
+ i += 1
19
+ end
20
+ end
21
+
22
+ bench.report("!nil?") do |times|
23
+ i = 0
24
+ while i < times
25
+ !x.nil?
26
+ i += 1
27
+ end
28
+ end
29
+
30
+ bench.report("nil !=") do |times|
31
+ i = 0
32
+ while i < times
33
+ nil != x
34
+ i += 1
35
+ end
36
+ end
37
+
38
+ bench.report("present?") do |times|
39
+ i = 0
40
+ while i < times
41
+ x.present?
42
+ i += 1
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ # When performing the initial testing we used `x == nil`. However, that was
49
+ # shockingly slow for the empty array case. Because of that we inverted the
50
+ # conditional in the above condition. However, as proof of this oddity and to
51
+ # allow us to track behavior in future versions we include this additional
52
+ # benchmark showing the issue.
53
+ section "Empty array `nil` comparison" do |bench|
54
+ x = []
55
+
56
+ bench.report("!= nil") do |times|
57
+ i = 0
58
+ while i < times
59
+ nil != x
60
+ i += 1
61
+ end
62
+ end
63
+
64
+ bench.report("nil !=") do |times|
65
+ i = 0
66
+ while i < times
67
+ x != nil
68
+ i += 1
69
+ end
70
+ end
71
+ end
72
+ # rubocop:enable Style/NonNilCheck
73
+
74
+ __END__
75
+
76
+ ### Environment
77
+
78
+ ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin16]
79
+ GC Disabled: true
80
+
81
+ ### Test Cases
82
+
83
+ #### nil
84
+
85
+ ```
86
+ Warming up --------------------------------------
87
+ !! 320.852k i/100ms
88
+ !nil? 313.833k i/100ms
89
+ nil != 330.298k i/100ms
90
+ present? 294.813k i/100ms
91
+ Calculating -------------------------------------
92
+ !! 41.841M (± 0.6%) i/s - 207.591M in 5.000435s
93
+ !nil? 30.851M (± 0.7%) i/s - 153.464M in 5.005301s
94
+ nil != 38.424M (± 0.5%) i/s - 191.573M in 5.007580s
95
+ present? 19.660M (± 0.7%) i/s - 97.878M in 4.999761s
96
+ with 95.0% confidence
97
+
98
+ Comparison:
99
+ !!: 41841263.8 i/s
100
+ nil !=: 38424408.4 i/s - 1.09x (± 0.01) slower
101
+ !nil?: 30850983.5 i/s - 1.36x (± 0.01) slower
102
+ present?: 19660459.4 i/s - 2.13x (± 0.02) slower
103
+ with 95.0% confidence
104
+ ```
105
+
106
+ #### []
107
+
108
+ ```
109
+ Warming up --------------------------------------
110
+ !! 317.562k i/100ms
111
+ !nil? 311.181k i/100ms
112
+ nil != 319.266k i/100ms
113
+ present? 293.159k i/100ms
114
+ Calculating -------------------------------------
115
+ !! 42.487M (± 0.6%) i/s - 211.179M in 5.005333s
116
+ !nil? 31.078M (± 0.5%) i/s - 154.968M in 5.005557s
117
+ nil != 38.313M (± 0.6%) i/s - 190.283M in 5.000799s
118
+ present? 21.854M (± 0.7%) i/s - 108.762M in 5.002198s
119
+ with 95.0% confidence
120
+
121
+ Comparison:
122
+ !!: 42487427.1 i/s
123
+ nil !=: 38312618.0 i/s - 1.11x (± 0.01) slower
124
+ !nil?: 31078123.9 i/s - 1.37x (± 0.01) slower
125
+ present?: 21854143.8 i/s - 1.94x (± 0.02) slower
126
+ with 95.0% confidence
127
+ ```
128
+
129
+ #### #<Object:0x00007f9c0a968310>
130
+
131
+ ```
132
+ Warming up --------------------------------------
133
+ !! 328.432k i/100ms
134
+ !nil? 307.084k i/100ms
135
+ nil != 324.749k i/100ms
136
+ present? 261.758k i/100ms
137
+ Calculating -------------------------------------
138
+ !! 40.897M (± 0.5%) i/s - 203.628M in 5.005426s
139
+ !nil? 30.242M (± 0.6%) i/s - 150.471M in 5.000563s
140
+ nil != 39.610M (± 0.6%) i/s - 197.123M in 5.005610s
141
+ present? 12.163M (± 0.8%) i/s - 60.728M in 5.011771s
142
+ with 95.0% confidence
143
+
144
+ Comparison:
145
+ !!: 40897495.2 i/s
146
+ nil !=: 39610078.3 i/s - 1.03x (± 0.01) slower
147
+ !nil?: 30242403.1 i/s - 1.35x (± 0.01) slower
148
+ present?: 12162705.7 i/s - 3.36x (± 0.03) slower
149
+ with 95.0% confidence
150
+ ```
151
+
152
+ #### Empty array `nil` comparison
153
+
154
+ ```
155
+ Warming up --------------------------------------
156
+ != nil 326.024k i/100ms
157
+ nil != 270.805k i/100ms
158
+ Calculating -------------------------------------
159
+ != nil 40.133M (± 0.5%) i/s - 199.853M in 5.004102s
160
+ nil != 11.551M (± 0.9%) i/s - 57.681M in 5.020992s
161
+ with 95.0% confidence
162
+
163
+ Comparison:
164
+ != nil: 40133046.7 i/s
165
+ nil !=: 11551012.8 i/s - 3.47x (± 0.04) slower
166
+ with 95.0% confidence
167
+ ```
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Run from the command line: bundle exec ruby benchmarks/empty_literal.rb
4
+ require_relative 'bm_setup'
5
+
6
+ display_benchmark_header
7
+
8
+ # rubocop:disable Style/EmptyLiteral
9
+ section "[] vs Array.new" do |bench|
10
+ bench.report("Array.new") do
11
+ Array.new
12
+ nil
13
+ end
14
+
15
+ bench.report("[]") do
16
+ []
17
+ nil
18
+ end
19
+ end
20
+
21
+ section "{} vs Hash.new" do |bench|
22
+ bench.report("Hash.new") do
23
+ Hash.new
24
+ nil
25
+ end
26
+
27
+ bench.report("{}") do
28
+ {}
29
+ nil
30
+ end
31
+ end
32
+ # rubocop:enable Style/EmptyLiteral
33
+
34
+ __END__
35
+
36
+ ### Environment
37
+
38
+ ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin16]
39
+ GC Disabled: false
40
+
41
+ ### Test Cases
42
+
43
+ #### [] vs Array.new
44
+
45
+ ```
46
+ Warming up --------------------------------------
47
+ Array.new 238.371k i/100ms
48
+ [] 336.249k i/100ms
49
+ Calculating -------------------------------------
50
+ Array.new 6.298M (± 1.0%) i/s - 31.465M in 5.014660s
51
+ [] 14.157M (± 0.8%) i/s - 70.612M in 5.004166s
52
+ with 95.0% confidence
53
+
54
+ Comparison:
55
+ []: 14157286.9 i/s
56
+ Array.new: 6297668.8 i/s - 2.25x (± 0.03) slower
57
+ with 95.0% confidence
58
+ ```
59
+
60
+ #### {} vs Hash.new
61
+
62
+ ```
63
+ Warming up --------------------------------------
64
+ Hash.new 140.548k i/100ms
65
+ {} 348.340k i/100ms
66
+ Calculating -------------------------------------
67
+ Hash.new 2.203M (± 1.1%) i/s - 11.103M in 5.056212s
68
+ {} 14.285M (± 0.6%) i/s - 71.410M in 5.010915s
69
+ with 95.0% confidence
70
+
71
+ Comparison:
72
+ {}: 14285184.2 i/s
73
+ Hash.new: 2202622.4 i/s - 6.49x (± 0.08) slower
74
+ with 95.0% confidence
75
+ ```