radius-spec 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/.travis.yml +2 -0
- data/CHANGELOG.md +24 -0
- data/Gemfile +7 -4
- data/benchmarks/bm_setup.rb +69 -0
- data/benchmarks/call_vs_yield.rb +148 -0
- data/benchmarks/case_equality_vs_class_check.rb +73 -0
- data/benchmarks/cover_vs_include.rb +106 -0
- data/benchmarks/delete_vs_tr.rb +100 -0
- data/benchmarks/double_negation.rb +167 -0
- data/benchmarks/empty_literal.rb +75 -0
- data/benchmarks/format_string.rb +58 -0
- data/benchmarks/format_string_token.rb +160 -0
- data/benchmarks/gsub_vs_tr.rb +95 -0
- data/benchmarks/hash_merge.rb +112 -0
- data/benchmarks/kwargs.rb +159 -0
- data/benchmarks/max_ternary.rb +105 -0
- data/benchmarks/max_ternary_micro.rb +129 -0
- data/benchmarks/unfreeze_string.rb +86 -0
- data/benchmarks/unpack_first.rb +54 -0
- data/bin/ci +1 -1
- data/bin/ci-code-review +28 -0
- data/common_rubocop.yml +83 -14
- data/lib/radius/spec/version.rb +1 -1
- data/radius-spec.gemspec +1 -0
- metadata +35 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 623e5f2ff9f43d04105288432e6c098baedf4a782cd079015ebeb7aeb1602d25
|
4
|
+
data.tar.gz: 5c06b3a06f58ea096cfd940c0366ae83b29254b5580cc53378e0004b36e55a2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2779d47b61810a6b0f7c079d4e4f993e9564f9e8c63b477e7a79907d857f0c36a00553cb888ea12a6d23d93fedc03193ae55e3e7481274b7e14dbcbcf0cd9b0d
|
7
|
+
data.tar.gz: ddd46b237b7fb16f1693ab44c2a1887b98056cebc03276674b1feedf1e8d456836f66ad1691229679cc8bcf9d45539daa2d3aff78043dcde7a3b52e540cf772f
|
data/.rubocop.yml
CHANGED
@@ -8,6 +8,7 @@ inherit_from: common_rubocop.yml
|
|
8
8
|
# Configuration parameters: CountComments, ExcludedMethods.
|
9
9
|
Metrics/BlockLength:
|
10
10
|
Exclude:
|
11
|
+
- 'benchmarks/**/*'
|
11
12
|
- 'lib/radius/spec/rspec.rb'
|
12
13
|
|
13
14
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,27 @@
|
|
1
|
+
## 0.3.0 (June 15, 2018)
|
2
|
+
|
3
|
+
[Full Changelog](https://github.com/RadiusNetworks/radius-spec/compare/v0.2.1...v0.3.0)
|
4
|
+
|
5
|
+
### Breaking Change
|
6
|
+
|
7
|
+
- Lock Rubocop to a minor release version in gemspec (Aaron Kromer, #5)
|
8
|
+
|
9
|
+
### Enhancements
|
10
|
+
|
11
|
+
- Adjust common Rubocop configuration (Aaron Kromer, #5)
|
12
|
+
- Customize `Style/AndOr` to flag only conditionals allowing `and` / `or` for
|
13
|
+
control flow
|
14
|
+
- Add `find` to functional method blocks
|
15
|
+
- Disable `Style/DoubleNegation` as this is a common Ruby idiom
|
16
|
+
- Disable `Style/StringLiteralsInInterpolation` to stay consistent with our
|
17
|
+
no preferences for single versus double quotes
|
18
|
+
|
19
|
+
### Bug Fixes
|
20
|
+
|
21
|
+
- Remove `Include` from common Rubocop all cops configuration to fix issues
|
22
|
+
with Rubocop 0.56.0+ not seeing all expected files. (Aaron Kromer, #5)
|
23
|
+
|
24
|
+
|
1
25
|
## 0.2.1 (May 17, 2018)
|
2
26
|
|
3
27
|
[Full Changelog](https://github.com/RadiusNetworks/radius-spec/compare/v0.2.0...v0.2.1)
|
data/Gemfile
CHANGED
@@ -7,15 +7,18 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
|
7
7
|
# Specify your gem's dependencies in radius-spec.gemspec
|
8
8
|
gemspec
|
9
9
|
|
10
|
+
group :benchmark, optional: true do
|
11
|
+
gem 'benchmark-ips', require: false
|
12
|
+
# TODO: See if this gem has an update in the future as it's gemspec is too
|
13
|
+
# strict and it was blocking other gems from installing / updating
|
14
|
+
gem 'kalibera', require: false, git: 'https://github.com/cupakromer/libkalibera.git'
|
15
|
+
end
|
16
|
+
|
10
17
|
group :debug do
|
11
18
|
gem "pry-byebug", "~> 3.6", require: false
|
12
19
|
gem "travis", require: false
|
13
20
|
end
|
14
21
|
|
15
|
-
group :development do
|
16
|
-
gem "rubocop", "~> 0.53", require: false
|
17
|
-
end
|
18
|
-
|
19
22
|
group :documentation do
|
20
23
|
gem 'yard', '~> 0.9', require: false
|
21
24
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'kalibera'
|
4
|
+
require 'benchmark/ips'
|
5
|
+
|
6
|
+
# Enable and start GC before each job run. Disable GC afterwards.
|
7
|
+
#
|
8
|
+
# Inspired by https://www.omniref.com/ruby/2.2.1/symbols/Benchmark/bm?#annotation=4095926&line=182
|
9
|
+
class GCSuite
|
10
|
+
def warming(*)
|
11
|
+
run_gc
|
12
|
+
end
|
13
|
+
|
14
|
+
def running(*)
|
15
|
+
run_gc
|
16
|
+
end
|
17
|
+
|
18
|
+
def warmup_stats(*)
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_report(*)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def run_gc
|
27
|
+
GC.enable
|
28
|
+
GC.start
|
29
|
+
GC.disable
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def as_boolean(val, default: nil)
|
34
|
+
case val.to_s.strip.downcase
|
35
|
+
when "true", "t", "yes", "y", "on", "1"
|
36
|
+
true
|
37
|
+
when "false", "f", "no", "n", "off", "0"
|
38
|
+
false
|
39
|
+
else
|
40
|
+
raise "Unknown boolean value #{val}" if default.nil?
|
41
|
+
default
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def section(title = nil)
|
46
|
+
puts "\n#### #{title}" if title
|
47
|
+
puts "\n```"
|
48
|
+
GC.start
|
49
|
+
Benchmark.ips do |bench|
|
50
|
+
bench.config suite: GCSuite.new if GC_DISABLED
|
51
|
+
bench.config stats: :bootstrap, confidence: 95
|
52
|
+
|
53
|
+
yield bench
|
54
|
+
bench.compare!
|
55
|
+
end
|
56
|
+
puts "```"
|
57
|
+
end
|
58
|
+
|
59
|
+
def display_benchmark_header
|
60
|
+
puts
|
61
|
+
puts "### Environment"
|
62
|
+
puts
|
63
|
+
puts RUBY_DESCRIPTION
|
64
|
+
puts "GC Disabled: #{GC_DISABLED}"
|
65
|
+
puts
|
66
|
+
puts "### Test Cases"
|
67
|
+
end
|
68
|
+
|
69
|
+
GC_DISABLED = as_boolean(ENV['GC_DISABLED'], default: false)
|
@@ -0,0 +1,148 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Run from the command line: bundle exec ruby benchmarks/call_vs_yield.rb
|
4
|
+
require_relative 'bm_setup'
|
5
|
+
|
6
|
+
display_benchmark_header
|
7
|
+
|
8
|
+
# rubocop:disable Performance/RedundantBlockCall
|
9
|
+
def block_call(&block)
|
10
|
+
block.call
|
11
|
+
end
|
12
|
+
|
13
|
+
def block_yield(&_block)
|
14
|
+
yield
|
15
|
+
end
|
16
|
+
|
17
|
+
def block_arg(&_block)
|
18
|
+
1 + 1 # Always do the same amount of work
|
19
|
+
end
|
20
|
+
|
21
|
+
def no_arg_yield
|
22
|
+
yield
|
23
|
+
end
|
24
|
+
|
25
|
+
def pass_through(&block)
|
26
|
+
no_arg_yield(&block)
|
27
|
+
end
|
28
|
+
|
29
|
+
section "Block call vs yield" do |bench|
|
30
|
+
bench.report("block.call") do |times|
|
31
|
+
i = 0
|
32
|
+
while i < times
|
33
|
+
block_call do
|
34
|
+
1 + 1
|
35
|
+
end
|
36
|
+
i += 1
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
bench.report("block yield") do |times|
|
41
|
+
i = 0
|
42
|
+
while i < times
|
43
|
+
block_yield do
|
44
|
+
1 + 1
|
45
|
+
end
|
46
|
+
i += 1
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
bench.report("block arg only") do |times|
|
51
|
+
i = 0
|
52
|
+
while i < times
|
53
|
+
block_arg do
|
54
|
+
1 + 1
|
55
|
+
end
|
56
|
+
i += 1
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
bench.report("no arg yield") do |times|
|
61
|
+
i = 0
|
62
|
+
while i < times
|
63
|
+
no_arg_yield do
|
64
|
+
1 + 1
|
65
|
+
end
|
66
|
+
i += 1
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
bench.report("pass through block") do |times|
|
71
|
+
i = 0
|
72
|
+
while i < times
|
73
|
+
pass_through do
|
74
|
+
1 + 1
|
75
|
+
end
|
76
|
+
i += 1
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
# rubocop:enable Performance/RedundantBlockCall
|
81
|
+
|
82
|
+
__END__
|
83
|
+
|
84
|
+
### Environment
|
85
|
+
|
86
|
+
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin16]
|
87
|
+
GC Disabled: false
|
88
|
+
|
89
|
+
### Test Cases
|
90
|
+
|
91
|
+
#### Block call vs yield
|
92
|
+
|
93
|
+
```
|
94
|
+
Warming up --------------------------------------
|
95
|
+
block.call 117.672k i/100ms
|
96
|
+
block yield 272.613k i/100ms
|
97
|
+
block arg only 287.821k i/100ms
|
98
|
+
no arg yield 286.217k i/100ms
|
99
|
+
pass through block 251.757k i/100ms
|
100
|
+
Calculating -------------------------------------
|
101
|
+
block.call 3.181M (± 0.9%) i/s - 15.886M in 5.010444s
|
102
|
+
block yield 14.017M (± 0.7%) i/s - 70.062M in 5.015163s
|
103
|
+
block arg only 17.835M (± 0.7%) i/s - 88.937M in 5.011243s
|
104
|
+
no arg yield 18.056M (± 0.6%) i/s - 90.158M in 5.010075s
|
105
|
+
pass through block 10.776M (± 0.8%) i/s - 53.876M in 5.019221s
|
106
|
+
with 95.0% confidence
|
107
|
+
|
108
|
+
Comparison:
|
109
|
+
no arg yield: 18056296.4 i/s
|
110
|
+
block arg only: 17835047.6 i/s - same-ish: difference falls within error
|
111
|
+
block yield: 14017426.6 i/s - 1.29x (± 0.01) slower
|
112
|
+
pass through block: 10776151.4 i/s - 1.68x (± 0.02) slower
|
113
|
+
block.call: 3180610.0 i/s - 5.68x (± 0.06) slower
|
114
|
+
with 95.0% confidence
|
115
|
+
```
|
116
|
+
|
117
|
+
### Environment
|
118
|
+
|
119
|
+
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin16]
|
120
|
+
GC Disabled: true
|
121
|
+
|
122
|
+
### Test Cases
|
123
|
+
|
124
|
+
#### Block call vs yield
|
125
|
+
|
126
|
+
```
|
127
|
+
Warming up --------------------------------------
|
128
|
+
block.call 134.623k i/100ms
|
129
|
+
block yield 276.955k i/100ms
|
130
|
+
block arg only 306.377k i/100ms
|
131
|
+
no arg yield 286.201k i/100ms
|
132
|
+
pass through block 259.025k i/100ms
|
133
|
+
Calculating -------------------------------------
|
134
|
+
block.call 3.558M (± 2.6%) i/s - 17.097M in 5.033155s
|
135
|
+
block yield 14.469M (± 0.7%) i/s - 72.285M in 5.013029s
|
136
|
+
block arg only 18.173M (± 0.6%) i/s - 90.688M in 5.005679s
|
137
|
+
no arg yield 18.207M (± 0.6%) i/s - 90.726M in 5.001766s
|
138
|
+
pass through block 10.794M (± 0.8%) i/s - 53.877M in 5.010781s
|
139
|
+
with 95.0% confidence
|
140
|
+
|
141
|
+
Comparison:
|
142
|
+
no arg yield: 18206595.2 i/s
|
143
|
+
block arg only: 18172764.0 i/s - same-ish: difference falls within error
|
144
|
+
block yield: 14469142.9 i/s - 1.26x (± 0.01) slower
|
145
|
+
pass through block: 10793657.6 i/s - 1.69x (± 0.02) slower
|
146
|
+
block.call: 3557929.5 i/s - 5.12x (± 0.14) slower
|
147
|
+
with 95.0% confidence
|
148
|
+
```
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Run from the command line: bundle exec ruby benchmarks/case_equality_vs_class_check.rb
|
4
|
+
require_relative 'bm_setup'
|
5
|
+
|
6
|
+
display_benchmark_header
|
7
|
+
|
8
|
+
section "Class match" do |bench|
|
9
|
+
x = "Any String"
|
10
|
+
|
11
|
+
bench.report("===") do
|
12
|
+
String === x # rubocop:disable Style/CaseEquality
|
13
|
+
end
|
14
|
+
|
15
|
+
bench.report("is_a?") do
|
16
|
+
x.is_a?(String)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
section "Class NO match" do |bench|
|
21
|
+
x = :any_symbol
|
22
|
+
|
23
|
+
bench.report("===") do
|
24
|
+
String === x # rubocop:disable Style/CaseEquality
|
25
|
+
end
|
26
|
+
|
27
|
+
bench.report("is_a?") do
|
28
|
+
x.is_a?(String)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
__END__
|
33
|
+
|
34
|
+
### Environment
|
35
|
+
|
36
|
+
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin16]
|
37
|
+
GC Disabled: true
|
38
|
+
|
39
|
+
### Test Cases
|
40
|
+
|
41
|
+
#### Class match
|
42
|
+
|
43
|
+
```
|
44
|
+
Warming up --------------------------------------
|
45
|
+
=== 284.703k i/100ms
|
46
|
+
is_a? 280.367k i/100ms
|
47
|
+
Calculating -------------------------------------
|
48
|
+
=== 11.394M (± 0.8%) i/s - 56.941M in 5.014392s
|
49
|
+
is_a? 11.068M (± 0.8%) i/s - 55.232M in 5.007549s
|
50
|
+
with 95.0% confidence
|
51
|
+
|
52
|
+
Comparison:
|
53
|
+
===: 11394313.8 i/s
|
54
|
+
is_a?: 11068062.4 i/s - 1.03x (± 0.01) slower
|
55
|
+
with 95.0% confidence
|
56
|
+
```
|
57
|
+
|
58
|
+
#### Class NO match
|
59
|
+
|
60
|
+
```
|
61
|
+
Warming up --------------------------------------
|
62
|
+
=== 298.288k i/100ms
|
63
|
+
is_a? 290.294k i/100ms
|
64
|
+
Calculating -------------------------------------
|
65
|
+
=== 10.567M (± 0.7%) i/s - 52.797M in 5.007023s
|
66
|
+
is_a? 10.405M (± 0.7%) i/s - 51.963M in 5.006983s
|
67
|
+
with 95.0% confidence
|
68
|
+
|
69
|
+
Comparison:
|
70
|
+
===: 10567130.4 i/s
|
71
|
+
is_a?: 10405382.6 i/s - 1.02x (± 0.01) slower
|
72
|
+
with 95.0% confidence
|
73
|
+
```
|
@@ -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
|
+
```
|