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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 57b3a65540f164d904d551fde0cf464302c215a7
4
- data.tar.gz: 91b1472c6e46cd77e839a5b86212254a07f577bb
3
+ metadata.gz: 0dd3fcc531f0566d64b9b9c7e9ece5232ab454d3
4
+ data.tar.gz: f2ea2351a8c48b3664cb24172c5168b62e75f634
5
5
  SHA512:
6
- metadata.gz: 7ed7667715c5b0207765e498b5454d678c2e00b53308679eda2930caf89b01164c55aaeeba3ca88bcfa0fdca9fd34723b0dd73b8fff839c5e070c3c6fcc06ba3
7
- data.tar.gz: 3aa206719ab05607b0a2016bdb1a524e4ccf2cf68171eba4fc5402695f2c0580a559643f8e59b918d73a48ec0c39d1e9b3e9cd870121ce16c15a9d6983100266
6
+ metadata.gz: 22e621015f4220a91d33f11390454518c09aa3177dd0a743aaf630f8eacead68d8aa06886e8b129906e71d84569258cdece067fc90578e78147ca97dc2eccde1
7
+ data.tar.gz: 87fdddd4f411ace4e590ba3d41b6ec1b3aa44006243e7bae97172a989c3e0fabe1d53cbdb24ca5d42df64577dd38e603539275b13a67d040abe38c0caf68cd05
@@ -1,3 +1,11 @@
1
+ v0.0.3 2015-07-26
2
+
3
+ ### Added
4
+
5
+ * `Condition#eql?` to compare complex conditions (nepalez)
6
+
7
+ [Compare v0.0.2...v0.0.3](https://github.com/nepalez/selector/compare/v0.0.2...v0.0.3)
8
+
1
9
  v0.0.2 2015-07-21
2
10
 
3
11
  ### Bugs fixed
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
 
@@ -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
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "ice_nine"
4
4
  require "singleton"
5
+ require "set"
5
6
 
6
7
  require_relative "selector/condition"
7
8
  require_relative "selector/anything"
@@ -37,6 +37,7 @@ module Selector
37
37
  def ==(other)
38
38
  other.instance_of?(self.class) && attributes.eql?(other.attributes)
39
39
  end
40
+ alias_method :eql?, :==
40
41
 
41
42
  # @!method [](value)
42
43
  # Checks if the value satisfies the condtion
@@ -4,6 +4,6 @@ module Selector
4
4
 
5
5
  # The semantic version of the gem.
6
6
  # @see http://semver.org/ Semantic versioning 2.0
7
- VERSION = "0.0.2".freeze
7
+ VERSION = "0.0.3".freeze
8
8
 
9
9
  end # module Selector
@@ -21,5 +21,6 @@ Gem::Specification.new do |gem|
21
21
  gem.add_runtime_dependency "ice_nine", "~> 0.11"
22
22
 
23
23
  gem.add_development_dependency "hexx-rspec", "~> 0.5"
24
+ gem.add_development_dependency "benchmark-ips", "~> 2.3"
24
25
 
25
26
  end # Gem::Specification
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ describe "Comparison" do
4
+
5
+ it "works" do
6
+ left = Selector.new(only: /foo/, except: /bar/)
7
+ right = Selector.new(only: /foo/, except: /bar/)
8
+
9
+ expect(left).to eql right
10
+ end
11
+
12
+ end # describe Comparison
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.2
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-21 00:00:00.000000000 Z
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