hashugar 0.0.2 → 0.0.3
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.
- data/.rvmrc +1 -1
- data/MIT-LICENSE +23 -0
- data/README.md +28 -12
- data/Rakefile +6 -0
- data/hashugar.gemspec +1 -0
- data/lib/hashugar/version.rb +1 -1
- data/lib/hashugar.rb +4 -0
- data/spec/hashugar_spec.rb +9 -0
- metadata +21 -11
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.9.3@hashugar --create
|
1
|
+
rvm use 1.9.3@hashugar --create
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
MIT LICENSE
|
2
|
+
|
3
|
+
Copyright (c) 2011 Sven Fuchs <svenfuchs@artweb-design.de>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
22
|
+
|
23
|
+
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
Hashugar
|
2
|
-
|
1
|
+
Hashugar (Hash Sugar)
|
2
|
+
=====================
|
3
|
+
|
4
|
+
[](http://travis-ci.org/jsuchal/hashugar)
|
3
5
|
|
4
6
|
Nested OpenStruct alternative optimized for speed especially for many short-lived objects (e.g. results from db).
|
5
7
|
|
@@ -20,29 +22,43 @@ hashugar.b.d.last.e # => 5
|
|
20
22
|
How fast is it?
|
21
23
|
---------------
|
22
24
|
|
25
|
+
Let's compare to the competitors - [OpenStruct](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/ostruct/rdoc/OpenStruct.html), [Hashr](https://github.com/svenfuchs/hashr)
|
26
|
+
|
27
|
+
`$ rake bench`
|
28
|
+
|
23
29
|
Ruby 1.9.3 benchmark
|
24
30
|
|
25
31
|
OpenStruct create small hash and access once
|
26
|
-
|
32
|
+
47458.0 (±3.4%) i/s - 238380 in 5.029038s (cycle=4110)
|
33
|
+
Hashr create small hash and access once
|
34
|
+
70290.2 (±3.1%) i/s - 356240 in 5.072827s (cycle=5840)
|
27
35
|
Hashugar create small hash and access once
|
28
|
-
|
36
|
+
873106.5 (±4.8%) i/s - 4381784 in 5.030829s (cycle=37774)
|
29
37
|
|
30
38
|
OpenStruct create big hash and access once
|
31
|
-
|
39
|
+
1028.3 (±3.0%) i/s - 5202 in 5.063657s (cycle=102)
|
40
|
+
Hashr create big hash and access once
|
41
|
+
3686.6 (±2.7%) i/s - 18615 in 5.053303s (cycle=365)
|
32
42
|
Hashugar create big hash and access once
|
33
|
-
|
43
|
+
839766.3 (±4.9%) i/s - 4199760 in 5.013690s (cycle=36840)
|
34
44
|
|
35
45
|
OpenStruct create small hash and access ten times
|
36
|
-
|
46
|
+
46554.1 (±2.8%) i/s - 234958 in 5.050963s (cycle=4051)
|
47
|
+
Hashr create small hash and access ten times
|
48
|
+
42768.0 (±2.4%) i/s - 216543 in 5.066085s (cycle=3799)
|
37
49
|
Hashugar create small hash and access ten times
|
38
|
-
|
50
|
+
121441.3 (±4.1%) i/s - 608597 in 5.021793s (cycle=9977)
|
39
51
|
|
40
52
|
OpenStruct create small hash and access fifty times
|
41
|
-
|
53
|
+
36047.5 (±2.8%) i/s - 181390 in 5.035970s (cycle=3298)
|
54
|
+
Hashr create small hash and access fifty times
|
55
|
+
15349.6 (±4.1%) i/s - 76752 in 5.008858s (cycle=1476)
|
42
56
|
Hashugar create small hash and access fifty times
|
43
|
-
|
57
|
+
23561.9 (±7.4%) i/s - 117250 in 5.005844s (cycle=2345)
|
44
58
|
|
45
59
|
OpenStruct create small hash and access hundred times
|
46
|
-
|
60
|
+
27801.2 (±5.8%) i/s - 139194 in 5.027806s (cycle=2442)
|
61
|
+
Hashr create small hash and access hundred times
|
62
|
+
8223.7 (±6.0%) i/s - 41463 in 5.061138s (cycle=813)
|
47
63
|
Hashugar create small hash and access hundred times
|
48
|
-
|
64
|
+
12406.0 (±3.8%) i/s - 61984 in 5.004111s (cycle=1192)
|
data/Rakefile
CHANGED
@@ -11,6 +11,7 @@ desc "Benchmark"
|
|
11
11
|
task :bench do
|
12
12
|
require 'benchmark/ips'
|
13
13
|
require 'ostruct'
|
14
|
+
require 'hashr'
|
14
15
|
require 'hashugar'
|
15
16
|
|
16
17
|
SMALL_HASH = {:a => 1, :b => 2}
|
@@ -18,18 +19,23 @@ task :bench do
|
|
18
19
|
|
19
20
|
Benchmark.ips do |x|
|
20
21
|
x.report 'OpenStruct create small hash and access once', 'OpenStruct.new(SMALL_HASH).item5'
|
22
|
+
x.report 'Hashr create small hash and access once', 'Hashr.new(SMALL_HASH).item5'
|
21
23
|
x.report 'Hashugar create small hash and access once', 'Hashugar.new(SMALL_HASH).item5'
|
22
24
|
|
23
25
|
x.report 'OpenStruct create big hash and access once', 'OpenStruct.new(BIG_HASH).item5'
|
26
|
+
x.report 'Hashr create big hash and access once', 'Hashr.new(BIG_HASH).item5'
|
24
27
|
x.report 'Hashugar create big hash and access once', 'Hashugar.new(BIG_HASH).item5'
|
25
28
|
|
26
29
|
x.report 'OpenStruct create small hash and access ten times', 'h = OpenStruct.new(SMALL_HASH); i = 0; while i < 10; h.a; i += 1; end'
|
30
|
+
x.report 'Hashr create small hash and access ten times', 'h = Hashr.new(SMALL_HASH); i = 0; while i < 10; h.a; i += 1; end'
|
27
31
|
x.report 'Hashugar create small hash and access ten times', 'h = Hashugar.new(SMALL_HASH); i = 0; while i < 10; h.a; i += 1; end'
|
28
32
|
|
29
33
|
x.report 'OpenStruct create small hash and access fifty times', 'h = OpenStruct.new(SMALL_HASH); i = 0; while i < 50; h.a; i += 1; end'
|
34
|
+
x.report 'Hashr create small hash and access fifty times', 'h = Hashr.new(SMALL_HASH); i = 0; while i < 50; h.a; i += 1; end'
|
30
35
|
x.report 'Hashugar create small hash and access fifty times', 'h = Hashugar.new(SMALL_HASH); i = 0; while i < 50; h.a; i += 1; end'
|
31
36
|
|
32
37
|
x.report 'OpenStruct create small hash and access hundred times', 'h = OpenStruct.new(SMALL_HASH); i = 0; while i < 100; h.a; i += 1; end'
|
38
|
+
x.report 'Hashr create small hash and access hundred times', 'h = Hashr.new(SMALL_HASH); i = 0; while i < 100; h.a; i += 1; end'
|
33
39
|
x.report 'Hashugar create small hash and access hundred times', 'h = Hashugar.new(SMALL_HASH); i = 0; while i < 100; h.a; i += 1; end'
|
34
40
|
end
|
35
41
|
end
|
data/hashugar.gemspec
CHANGED
data/lib/hashugar/version.rb
CHANGED
data/lib/hashugar.rb
CHANGED
data/spec/hashugar_spec.rb
CHANGED
@@ -57,4 +57,13 @@ describe Hashugar do
|
|
57
57
|
hashugar.last.b.should == 2
|
58
58
|
end
|
59
59
|
end
|
60
|
+
|
61
|
+
context 'when using respond_to?' do
|
62
|
+
it 'should return true on valid key' do
|
63
|
+
hashugar = {:a => 1}.to_hashugar
|
64
|
+
hashugar.respond_to?('a').should be_true
|
65
|
+
hashugar.respond_to?(:a).should be_true
|
66
|
+
hashugar.respond_to?(:b).should be_false
|
67
|
+
end
|
68
|
+
end
|
60
69
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashugar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &19545860 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *19545860
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: benchmark_suite
|
27
|
-
requirement: &
|
27
|
+
requirement: &19545380 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *19545380
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: ffi
|
38
|
-
requirement: &
|
38
|
+
requirement: &19544920 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,18 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *19544920
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: hashr
|
49
|
+
requirement: &19544220 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *19544220
|
47
58
|
description: Nested OpenStruct optimized for short-lived objects.
|
48
59
|
email:
|
49
60
|
- johno@jsmf.net
|
@@ -54,6 +65,7 @@ files:
|
|
54
65
|
- .gitignore
|
55
66
|
- .rvmrc
|
56
67
|
- Gemfile
|
68
|
+
- MIT-LICENSE
|
57
69
|
- README.md
|
58
70
|
- Rakefile
|
59
71
|
- TODO
|
@@ -86,6 +98,4 @@ rubygems_version: 1.8.10
|
|
86
98
|
signing_key:
|
87
99
|
specification_version: 3
|
88
100
|
summary: Fast Nested OpenStruct
|
89
|
-
test_files:
|
90
|
-
- spec/hashugar_spec.rb
|
91
|
-
- spec/spec_helper.rb
|
101
|
+
test_files: []
|