selector 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +12 -0
- data/benchmark/run.rb +112 -0
- data/lib/selector.rb +1 -0
- data/lib/selector/condition.rb +1 -0
- data/lib/selector/version.rb +1 -1
- data/selector.gemspec +1 -0
- data/spec/integration/comparison_spec.rb +12 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0dd3fcc531f0566d64b9b9c7e9ece5232ab454d3
|
4
|
+
data.tar.gz: f2ea2351a8c48b3664cb24172c5168b62e75f634
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22e621015f4220a91d33f11390454518c09aa3177dd0a743aaf630f8eacead68d8aa06886e8b129906e71d84569258cdece067fc90578e78147ca97dc2eccde1
|
7
|
+
data.tar.gz: 87fdddd4f411ace4e590ba3d41b6ec1b3aa44006243e7bae97172a989c3e0fabe1d53cbdb24ca5d42df64577dd38e603539275b13a67d040abe38c0caf68cd05
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -98,6 +98,18 @@ selector[2.5] # => false
|
|
98
98
|
Selector.new.frozen? # => true
|
99
99
|
```
|
100
100
|
|
101
|
+
Performance
|
102
|
+
-----------
|
103
|
+
|
104
|
+
Use the gem when you really need:
|
105
|
+
|
106
|
+
* unified interface, agnostic to the types of conditions.
|
107
|
+
* composition of various conditions.
|
108
|
+
|
109
|
+
The selector is slow. And the simpler the condition, the more the cost in terms of performance, that can vary from x1.45 for functions to x3.5 for simple comparison.
|
110
|
+
|
111
|
+
For details see the [benchmark](https://github.com/nepalez/selector/blob/master/benchmark/run.rb) and [its results](https://github.com/nepalez/selector/wiki/Benchmark).
|
112
|
+
|
101
113
|
Installation
|
102
114
|
------------
|
103
115
|
|
data/benchmark/run.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
require "selector"
|
2
|
+
require "benchmark/ips"
|
3
|
+
|
4
|
+
puts "============================================================"
|
5
|
+
puts "Equality"
|
6
|
+
puts "value == :foo"
|
7
|
+
puts "============================================================"
|
8
|
+
|
9
|
+
Benchmark.ips do |x|
|
10
|
+
x.config time: 10, warmup: 5
|
11
|
+
|
12
|
+
value = :foo
|
13
|
+
selector = Selector.new only: :foo
|
14
|
+
|
15
|
+
x.report("Selector") do
|
16
|
+
selector[:foo]
|
17
|
+
end
|
18
|
+
|
19
|
+
x.report("Native") do
|
20
|
+
value == :foo
|
21
|
+
end
|
22
|
+
|
23
|
+
x.compare!
|
24
|
+
end
|
25
|
+
|
26
|
+
puts "============================================================"
|
27
|
+
puts "Presence in array"
|
28
|
+
puts "[:foo, :bar].include? value"
|
29
|
+
puts "============================================================"
|
30
|
+
|
31
|
+
Benchmark.ips do |x|
|
32
|
+
x.config time: 10, warmup: 5
|
33
|
+
|
34
|
+
array = [:foo, :bar]
|
35
|
+
selector = Selector.new only: [:foo, :bar]
|
36
|
+
|
37
|
+
x.report("Selector") do
|
38
|
+
selector[:foo]
|
39
|
+
end
|
40
|
+
|
41
|
+
x.report("Native") do
|
42
|
+
array.include? :foo
|
43
|
+
end
|
44
|
+
|
45
|
+
x.compare!
|
46
|
+
end
|
47
|
+
|
48
|
+
puts "============================================================"
|
49
|
+
puts "Presence in a range"
|
50
|
+
puts "(1..3).include? value"
|
51
|
+
puts "============================================================"
|
52
|
+
|
53
|
+
Benchmark.ips do |x|
|
54
|
+
x.config time: 10, warmup: 5
|
55
|
+
|
56
|
+
range = 1..3
|
57
|
+
selector = Selector.new only: range
|
58
|
+
|
59
|
+
x.report("Selector") do
|
60
|
+
selector[2.1]
|
61
|
+
end
|
62
|
+
|
63
|
+
x.report("Native") do
|
64
|
+
range.include? 2.1
|
65
|
+
end
|
66
|
+
|
67
|
+
x.compare!
|
68
|
+
end
|
69
|
+
|
70
|
+
puts "============================================================"
|
71
|
+
puts "Matching regexp"
|
72
|
+
puts "value.to_s[/1/]"
|
73
|
+
puts "============================================================"
|
74
|
+
|
75
|
+
Benchmark.ips do |x|
|
76
|
+
x.config time: 10, warmup: 5
|
77
|
+
|
78
|
+
regexp = /1/
|
79
|
+
selector = Selector.new only: regexp
|
80
|
+
|
81
|
+
x.report("Selector") do
|
82
|
+
selector[1]
|
83
|
+
end
|
84
|
+
|
85
|
+
x.report("Native") do
|
86
|
+
1.to_s[regexp]
|
87
|
+
end
|
88
|
+
|
89
|
+
x.compare!
|
90
|
+
end
|
91
|
+
|
92
|
+
puts "============================================================"
|
93
|
+
puts "Result of function call"
|
94
|
+
puts "proc { |value| value == :foo }.call(value) ? true : false"
|
95
|
+
puts "============================================================"
|
96
|
+
|
97
|
+
Benchmark.ips do |x|
|
98
|
+
x.config time: 10, warmup: 5
|
99
|
+
|
100
|
+
function = -> v { v == :foo }
|
101
|
+
selector = Selector.new only: function
|
102
|
+
|
103
|
+
x.report("Selector") do
|
104
|
+
selector[:foo]
|
105
|
+
end
|
106
|
+
|
107
|
+
x.report("Native") do
|
108
|
+
function.call(:foo) ? true : false
|
109
|
+
end
|
110
|
+
|
111
|
+
x.compare!
|
112
|
+
end
|
data/lib/selector.rb
CHANGED
data/lib/selector/condition.rb
CHANGED
data/lib/selector/version.rb
CHANGED
data/selector.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: selector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kozin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ice_nine
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: benchmark-ips
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.3'
|
41
55
|
description:
|
42
56
|
email: andrew.kozin@gmail.com
|
43
57
|
executables: []
|
@@ -59,6 +73,7 @@ files:
|
|
59
73
|
- LICENSE
|
60
74
|
- README.md
|
61
75
|
- Rakefile
|
76
|
+
- benchmark/run.rb
|
62
77
|
- config/metrics/STYLEGUIDE
|
63
78
|
- config/metrics/cane.yml
|
64
79
|
- config/metrics/churn.yml
|
@@ -84,6 +99,7 @@ files:
|
|
84
99
|
- lib/selector/version.rb
|
85
100
|
- selector.gemspec
|
86
101
|
- spec/integration/blacklist_spec.rb
|
102
|
+
- spec/integration/comparison_spec.rb
|
87
103
|
- spec/integration/composition_spec.rb
|
88
104
|
- spec/integration/negation_spec.rb
|
89
105
|
- spec/integration/whitelist_spec.rb
|
@@ -129,6 +145,7 @@ test_files:
|
|
129
145
|
- spec/integration/composition_spec.rb
|
130
146
|
- spec/integration/whitelist_spec.rb
|
131
147
|
- spec/integration/blacklist_spec.rb
|
148
|
+
- spec/integration/comparison_spec.rb
|
132
149
|
- spec/integration/negation_spec.rb
|
133
150
|
- spec/unit/selector_spec.rb
|
134
151
|
- spec/unit/selector/anything_spec.rb
|