astruct 2.7.1 → 2.9.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 @@
1
+ - 1.9.3
@@ -0,0 +1,26 @@
1
+ require 'benchmark/ips'
2
+ require 'astruct'
3
+ require 'ostruct'
4
+
5
+ DATA = (1..10_000).map { |i| { :"item#{i}" => i } }.inject :merge!
6
+ DATA2 = (10_000..20_000).map { |i| { :"item#{i}" => i } }.inject :merge!
7
+
8
+ Benchmark.ips do |x|
9
+ x.report "OStruct new with data then load with more data" do
10
+ class OProfile < OpenStruct; end
11
+ op = OProfile.new DATA.dup
12
+ op.marshal_load DATA2.dup
13
+ end
14
+
15
+ x.report "AStruct new with data then load with more data" do
16
+ class AProfile < AltStruct; end
17
+ ap = AProfile.new DATA.dup
18
+ ap.load DATA2.dup
19
+ end
20
+ end
21
+ # Calculating -------------------------------------
22
+ # OStruct new with data then load with more data 1 i/100ms
23
+ # AStruct new with data then load with more data 1 i/100ms
24
+ # -------------------------------------------------
25
+ # OStruct new with data then load with more data 3.2 (±0.0%) i/s - 16 in 5.032341s
26
+ # AStruct new with data then load with more data 4.4 (±23.0%) i/s - 21 in 5.033214s
@@ -0,0 +1,25 @@
1
+ require 'benchmark/ips'
2
+ require 'astruct'
3
+ require 'ostruct'
4
+
5
+ DATA = (1..10_000).map { |i| { :"item#{i}" => i } }.inject :merge!
6
+
7
+ Benchmark.ips do |x|
8
+ x.report "OStruct new with data then delete" do
9
+ class OProfile < OpenStruct; end
10
+ op = OProfile.new DATA.dup
11
+ op.delete_field :item1
12
+ end
13
+
14
+ x.report "AStruct new with data then delete" do
15
+ class AProfile < AltStruct; end
16
+ ap = AProfile.new DATA.dup
17
+ ap.delete :item1
18
+ end
19
+ end
20
+ # Calculating -------------------------------------
21
+ # OStruct new with data then delete 1 i/100ms
22
+ # AStruct new with data then delete 1 i/100ms
23
+ # -------------------------------------------------
24
+ # OStruct new with data then delete 8.9 (±11.3%) i/s - 44 in 5.014542s
25
+ # AStruct new with data then delete 10.2 (±29.5%) i/s - 48 in 5.014586s
@@ -0,0 +1,25 @@
1
+ require 'benchmark/ips'
2
+ require 'astruct'
3
+ require 'ostruct'
4
+
5
+ DATA = (1..10_000).map { |i| { :"item#{i}" => i } }.inject :merge!
6
+
7
+ Benchmark.ips do |x|
8
+ x.report "OStruct dump with data" do
9
+ class OProfile < OpenStruct; end
10
+ op = OProfile.new DATA.dup
11
+ op.marshal_dump
12
+ end
13
+
14
+ x.report "AStruct dump with data" do
15
+ class AProfile < AltStruct; end
16
+ ap = AProfile.new DATA.dup
17
+ ap.dump
18
+ end
19
+ end
20
+ # Calculating -------------------------------------
21
+ # OStruct dump with data 1 i/100ms
22
+ # AStruct dump with data 1 i/100ms
23
+ # -------------------------------------------------
24
+ # OStruct dump with data 9.0 (±22.2%) i/s - 44 in 5.055799s
25
+ # AStruct dump with data 10.2 (±29.4%) i/s - 48 in 5.073042s
@@ -0,0 +1,29 @@
1
+ require 'benchmark/ips'
2
+ require 'astruct'
3
+ require 'ostruct'
4
+
5
+ DATA = (1..10_000).map { |i| { :"item#{i}" => i } }.inject :merge!
6
+
7
+ Benchmark.ips do |x|
8
+ x.report "OStruct new with data then assign new data" do
9
+ class OProfile < OpenStruct; end
10
+ op = OProfile.new DATA.dup
11
+ op.example1 = "red"
12
+ op.example2 = "blue"
13
+ op.example3 = "green"
14
+ end
15
+
16
+ x.report "AStructt new with data then assign new data" do
17
+ class AProfile < AltStruct; end
18
+ ap = AProfile.new DATA.dup
19
+ ap.example1 = "red"
20
+ ap.example2 = "blue"
21
+ ap.example3 = "green"
22
+ end
23
+ end
24
+ # Calculating -------------------------------------
25
+ # OStruct new with data then assign new data 1 i/100ms
26
+ # AStructt new with data then assign new data 1 i/100ms
27
+ # -------------------------------------------------
28
+ # OStruct new with data then assign new data 8.5 (±11.8%) i/s - 42 in 5.078029s
29
+ # AStructt new with data then assign new data 9.4 (±32.0%) i/s - 43 in 5.005849s
@@ -0,0 +1,25 @@
1
+ require 'benchmark/ips'
2
+ require 'astruct'
3
+ require 'ostruct'
4
+
5
+ DATA = (1..10_000).map { |i| { :"item#{i}" => i } }.inject :merge!
6
+
7
+ Benchmark.ips do |x|
8
+ x.report "OStruct inspect with data" do
9
+ class OProfile < OpenStruct; end
10
+ op = OProfile.new DATA.dup
11
+ op.inspect
12
+ end
13
+
14
+ x.report "AStruct inspect with data" do
15
+ class AProfile < AltStruct; end
16
+ ap = AProfile.new DATA.dup
17
+ ap.inspect
18
+ end
19
+ end
20
+ # Calculating -------------------------------------
21
+ # OStruct inspect with data 1 i/100ms
22
+ # AStruct inspect with data 1 i/100ms
23
+ # -------------------------------------------------
24
+ # OStruct inspect with data 8.2 (±24.4%) i/s - 40 in 5.085258s
25
+ # AStruct inspect with data 9.1 (±21.9%) i/s - 45 in 5.063373s
@@ -0,0 +1,25 @@
1
+ require 'benchmark/ips'
2
+ require 'astruct'
3
+ require 'ostruct'
4
+
5
+ DATA = (1..10_000).map { |i| { :"item#{i}" => i } }.inject :merge!
6
+
7
+ Benchmark.ips do |x|
8
+ x.report "OStruct load with data" do
9
+ class OProfile < OpenStruct; end
10
+ op = OProfile.new
11
+ op.marshal_load DATA.dup
12
+ end
13
+
14
+ x.report "AStruct load with data" do
15
+ class AProfile < AltStruct; end
16
+ ap = AProfile.new
17
+ ap.load DATA.dup
18
+ end
19
+ end
20
+ # Calculating -------------------------------------
21
+ # OStruct load with data 1 i/100ms
22
+ # AStruct load with data 1 i/100ms
23
+ # -------------------------------------------------
24
+ # OStruct load with data 10.1 (±19.9%) i/s - 49 in 5.017475s
25
+ # AStruct load with data 10.3 (±29.1%) i/s - 50 in 5.090294s
@@ -0,0 +1,29 @@
1
+ require 'benchmark/ips'
2
+ require 'astruct'
3
+ require 'ostruct'
4
+
5
+ DATA = (1..10_000).map { |i| { :"item#{i}" => i } }.inject :merge!
6
+
7
+ Benchmark.ips do |x|
8
+ x.report "OStruct new with data then 3 deep and inspect" do
9
+ class OProfile < OpenStruct; end
10
+ op = OProfile.new DATA.dup
11
+ op.op2 = OProfile.new DATA.dup
12
+ op.op2.op3 = OProfile.new DATA.dup
13
+ op.inspect
14
+ end
15
+
16
+ x.report "AStruct new with data then 3 deep and inspect" do
17
+ class AProfile < AltStruct; end
18
+ ap = AProfile.new DATA.dup
19
+ ap.ap2 = AProfile.new DATA.dup
20
+ ap.ap2.ap3 = AProfile.new DATA.dup
21
+ ap.inspect
22
+ end
23
+ end
24
+ # Calculating -------------------------------------
25
+ # OStruct new with data then 3 deep and inspect 1 i/100ms
26
+ # AStruct new with data then 3 deep and inspect 1 i/100ms
27
+ # -------------------------------------------------
28
+ # OStruct new with data then 3 deep and inspect 2.0 (±0.0%) i/s - 10 in 5.184739s
29
+ # AStruct new with data then 3 deep and inspect 3.1 (±31.9%) i/s - 15 in 5.029310s
@@ -0,0 +1,23 @@
1
+ require 'benchmark/ips'
2
+ require 'astruct'
3
+ require 'ostruct'
4
+
5
+ DATA = (1..10_000).map { |i| { :"item#{i}" => i } }.inject :merge!
6
+
7
+ Benchmark.ips do |x|
8
+ x.report "OStruct new with data" do
9
+ class OProfile < OpenStruct; end
10
+ OProfile.new DATA.dup
11
+ end
12
+
13
+ x.report "AStruct new with data" do
14
+ class AProfile < AltStruct; end
15
+ AProfile.new DATA.dup
16
+ end
17
+ end
18
+ # Calculating -------------------------------------
19
+ # OStruct new with data 1 i/100ms
20
+ # AStruct new with data 1 i/100ms
21
+ # -------------------------------------------------
22
+ # OStruct new with data 8.6 (±23.2%) i/s - 42 in 5.041086s
23
+ # AStruct new with data 9.7 (±30.8%) i/s - 47 in 5.101214s
@@ -2,6 +2,8 @@ class AltStruct
2
2
  module M
3
3
  ThreadKey = :__inspect_astruct_ids__ # :nodoc:
4
4
  attr_reader :table
5
+ alias_method :__object_id__, :object_id
6
+ alias_method :__singleton_class__, :singleton_class
5
7
 
6
8
  # Create a new field for each of the key/value pairs passed.
7
9
  # By default the resulting OpenStruct object will have no
@@ -58,8 +60,8 @@ class AltStruct
58
60
  # The delete_field() method removes a key/value pair on the @table
59
61
  # and on the singleton class. It also mimics the Hash#delete method.
60
62
  def __delete_field__(key)
61
- singleton_class.send :remove_method, key
62
- singleton_class.send :remove_method, :"#{key}="
63
+ __singleton_class__.send :remove_method, key
64
+ __singleton_class__.send :remove_method, :"#{key}="
63
65
  @table.delete key
64
66
  end
65
67
  alias_method :delete_field, :__delete_field__
@@ -96,6 +98,8 @@ class AltStruct
96
98
  super
97
99
  @table.freeze
98
100
  end
101
+ alias_method :__freeze__, :freeze
102
+ alias_method :__frozen?, :frozen?
99
103
 
100
104
  private
101
105
 
@@ -141,7 +145,7 @@ class AltStruct
141
145
  end
142
146
 
143
147
  def __id_exists_in_id_list?
144
- Thread.current[ThreadKey].include?(object_id)
148
+ Thread.current[ThreadKey].include?(__object_id__)
145
149
  end
146
150
 
147
151
  def __remove_last_id_from_id_list__
@@ -1,4 +1,4 @@
1
1
  class AltStruct
2
2
  # This is the AltStruct version
3
- VERSION = "2.7.1"
3
+ VERSION = "2.9.0"
4
4
  end
@@ -150,10 +150,6 @@ class TestAltStruct < MiniTest::Unit::TestCase
150
150
  assert_equal expected, actual
151
151
  end
152
152
 
153
- def test_example_has_table_method
154
- assert_respond_to @example, :table
155
- end
156
-
157
153
  def test_empty_example_has_empty_table
158
154
  expected = {}
159
155
  actual = @empty.table
@@ -207,10 +203,6 @@ class TestAltStruct < MiniTest::Unit::TestCase
207
203
  assert_equal expected, actual
208
204
  end
209
205
 
210
- def test_example_has_dump_method
211
- assert_respond_to @example, :dump
212
- end
213
-
214
206
  def test_dump_contains_values
215
207
  expected = { name: "Kurtis", age: 24 }
216
208
  actual = @example.dump
@@ -233,4 +225,3 @@ class TestAltStruct < MiniTest::Unit::TestCase
233
225
  refute_respond_to @empty, :name
234
226
  end
235
227
  end
236
-
@@ -0,0 +1,227 @@
1
+ require 'minitest/autorun'
2
+ require_relative '../helper'
3
+
4
+ class TestOpenStruct < MiniTest::Unit::TestCase
5
+ def setup
6
+ @empty = OpenStruct.new
7
+ @example = OpenStruct.new name: "Kurtis", age: 24
8
+ end
9
+
10
+ def test_equality_with_two_empty_ostructs
11
+ empty2 = OpenStruct.new
12
+ assert_equal @empty, empty2
13
+ end
14
+
15
+ def test_equality_vs_ostruct_with_fields
16
+ refute_equal @example, @empty
17
+ end
18
+
19
+ def test_equality_vs_object_with_fake_table
20
+ empty_object = Object.new
21
+ empty_object.instance_eval { @table = { name: "Kurtis", age: 24 } }
22
+ expected = @example
23
+ actual = empty_object
24
+ refute_equal expected, actual
25
+ end
26
+
27
+ def test_inspect_with_no_fields
28
+ expected = "#<OpenStruct>"
29
+ actual = @empty.inspect
30
+ assert_equal expected, actual
31
+ end
32
+
33
+ def test_inspect_with_fields
34
+ @empty.example1 = 1
35
+ @empty.example2 = 2
36
+ expected = "#<OpenStruct example1=1, example2=2>"
37
+ actual = @empty.inspect
38
+ assert_equal expected, actual
39
+ end
40
+
41
+ def test_inspect_with_sub_struct_duplicate
42
+ @empty.struct2 = OpenStruct.new
43
+ @empty.struct2.struct3 = @empty
44
+ expected = '#<OpenStruct struct2=#<OpenStruct struct3=#<OpenStruct ...>>>'
45
+ actual = @empty.inspect
46
+ assert_equal expected, actual
47
+ end
48
+
49
+ def test_inspect_with_sub_struct
50
+ @example.friends = OpenStruct.new name: "Jason", age: 24
51
+ @example.friends.friends = OpenStruct.new name: "John", age: 15
52
+ @example.friends.friends.friends = OpenStruct.new name: "Ally", age: 32
53
+ expected = '#<OpenStruct name="Kurtis", age=24, friends=#<OpenStruct name="Jason", age=24, friends=#<OpenStruct name="John", age=15, friends=#<OpenStruct name="Ally", age=32>>>>'
54
+ actual = @example.inspect
55
+ assert_equal expected, actual
56
+ end
57
+
58
+ def test_inspect_with_twice_inspected_struct
59
+ @example.inspect
60
+ @example.inspect
61
+ expected = '#<OpenStruct name="Kurtis", age=24>'
62
+ actual = @example.inspect
63
+ assert_equal expected, actual
64
+ end
65
+
66
+ def test_inspect_with_empty_sub_struct
67
+ @empty.struct2 = OpenStruct.new
68
+ expected = '#<OpenStruct struct2=#<OpenStruct>>'
69
+ actual = @empty.inspect
70
+ assert_equal expected, actual
71
+ end
72
+
73
+ def test_freeze_stops_new_assignments
74
+ @example.freeze
75
+ assert_raises(RuntimeError) { @example.age = 24 }
76
+ end
77
+
78
+ def test_freeze_still_returns_values
79
+ @example.freeze
80
+ expecteds = "Kurtis"
81
+ actual = @example.name
82
+ assert_equal expecteds, actual
83
+ end
84
+
85
+ def test_freeze_stops_reassignments
86
+ @example.freeze
87
+ assert_raises(RuntimeError) { @example.name = "Jazzy" }
88
+ end
89
+
90
+ # def test_freeze_stops_reassign_even_if_frozen_redefined
91
+ # @example.freeze
92
+ # def @example.frozen?; nil end
93
+ # @example.freeze
94
+ # message = '[ruby-core:22559]'
95
+ # assert_raises(RuntimeError, message) { @example.name = "Jazzy" }
96
+ # # assert_raises(TypeError, message) { @example.name = "Jazzy" }
97
+ # end
98
+
99
+ def test_ostruct_doesn_respond_to_non_existant_keys_getter
100
+ refute_respond_to @empty, :akey
101
+ end
102
+
103
+ def test_ostruct_doesn_respond_to_non_existant_keys_setter
104
+ refute_respond_to @empty, :akey=
105
+ end
106
+
107
+ def test_delete_field_removes_getter_method
108
+ bug = '[ruby-core:33010]'
109
+ @example.delete_field :name
110
+ refute_respond_to @example, :name, bug
111
+ end
112
+
113
+ def test_delete_field_removes_setter_method
114
+ bug = '[ruby-core:33010]'
115
+ @example.delete_field :name
116
+ refute_respond_to @example, :name=, bug
117
+ end
118
+
119
+ def test_delete_field_removes_table_key_value
120
+ @example.delete_field :name
121
+ expected = nil
122
+ actual = @example.table[:name]
123
+ assert_equal expected, actual
124
+ end
125
+
126
+ def test_delete_field_returns_value_of_deleted_key
127
+ expected = "Kurtis"
128
+ actual = @example.delete_field :name
129
+ assert_equal expected, actual
130
+ end
131
+
132
+ def test_method_missing_handles_square_bracket_equals
133
+ assert_raises(ArgumentError) { @empty[:foo] = :bar }
134
+ end
135
+
136
+ def test_method_missing_handles_square_brackets
137
+ assert_raises(NoMethodError) { @empty[:foo] }
138
+ end
139
+
140
+ def test_to_hash_returns_hash
141
+ expected = { name: "John Smith", age: 70, pension: 300 }
142
+ actual = OpenStruct.new(expected).to_hash
143
+ assert_equal expected, actual
144
+ end
145
+
146
+ def test_to_hash_modified_modifies_ostruct
147
+ @example.to_hash[:age] = 70
148
+ expected = 70
149
+ actual = @example.age
150
+ assert_equal expected, actual
151
+ end
152
+
153
+ def test_empty_example_has_empty_table
154
+ expected = {}
155
+ actual = @empty.table
156
+ assert_equal expected, actual
157
+ end
158
+
159
+ def test_example_has_name_method
160
+ assert_respond_to @example, :name
161
+ end
162
+
163
+ def test_example_has_given_name
164
+ expected = "Kurtis"
165
+ actual = @example.name
166
+ assert_equal expected, actual
167
+ end
168
+
169
+ def test_example_takes_name
170
+ assert_send [@example, :name=, "Dave"]
171
+ end
172
+
173
+ def test_example_has_taken_name
174
+ @example.name = "Dave"
175
+ expected = "Dave"
176
+ actual = @example.name
177
+ assert_equal expected, actual
178
+ end
179
+
180
+ def test_load_takes_a_hash
181
+ assert_send [@example, :load, { nickname: "Kurt" }]
182
+ end
183
+
184
+ def test_load_sets_methods
185
+ @example.load nickname: "Kurt"
186
+ assert_respond_to @example, :nickname
187
+ end
188
+
189
+ def test_ostruct_has_getter_methods_with_non_alpha_numeric_characters
190
+ @example.load "Length (In Inchs)" => 72
191
+ assert_send [@example, :"Length (In Inchs)"]
192
+ end
193
+
194
+ def test_ostruct_has_getter_methods_with_non_alpha_numeric_characters
195
+ @example.load "Length (In Inchs)" => 72
196
+ assert_send [@example, :"Length (In Inchs)=", 73]
197
+ end
198
+
199
+ def test_load_sets_correct_value
200
+ @example.load nickname: "Kurt"
201
+ expected = "Kurt"
202
+ actual = @example.nickname
203
+ assert_equal expected, actual
204
+ end
205
+
206
+ def test_dump_contains_values
207
+ expected = { name: "Kurtis", age: 24 }
208
+ actual = @example.marshal_dump
209
+ assert_equal expected, actual
210
+ end
211
+
212
+ def test_selective_dump_contains_selective_values
213
+ expected = { age: 24 }
214
+ actual = @example.dump :age
215
+ assert_equal expected, actual
216
+ end
217
+
218
+ def test_inspect_has_values_delimited_by_comma
219
+ expected = /name="Kurtis", age=24/
220
+ actual = @example.inspect
221
+ assert_match expected, actual
222
+ end
223
+
224
+ def test_other_object_isnt_affected
225
+ refute_respond_to @empty, :name
226
+ end
227
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: astruct
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.1
4
+ version: 2.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-24 00:00:00.000000000 Z
12
+ date: 2012-08-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -84,24 +84,27 @@ extra_rdoc_files: []
84
84
  files:
85
85
  - .gitignore
86
86
  - .rvmrc
87
+ - .travis.yml
87
88
  - Gemfile
88
89
  - Guardfile
89
90
  - LICENSE
90
91
  - README.md
91
92
  - Rakefile
92
93
  - astruct.gemspec
93
- - benchmark/basic_vs_ostruct.rb
94
- - benchmark/deep_inspect_vs_ostruct.rb
95
- - benchmark/delete_vs_ostruct.rb
96
- - benchmark/dump_vs_ostruct.rb
97
- - benchmark/dynamic_vs_ostruct
98
- - benchmark/inspect_vs_ostruct.rb
99
- - benchmark/load_vs_ostruct.rb
94
+ - bench/add_more_vs_ostruct.rb
95
+ - bench/delete_vs_ostruct.rb
96
+ - bench/dump_vs_ostruct.rb
97
+ - bench/dynamic_vs_ostruct.rb
98
+ - bench/inspect_vs_ostruct.rb
99
+ - bench/load_vs_ostruct.rb
100
+ - bench/nested_vs_ostruct.rb
101
+ - bench/new_vs_ostruct.rb
100
102
  - lib/astruct.rb
101
103
  - lib/astruct/module.rb
102
104
  - lib/astruct/version.rb
103
105
  - test/helper.rb
104
106
  - test/lib/astruct_test.rb
107
+ - test/lib/ostruct_test.rb
105
108
  homepage: http://krainboltgreene.github.com/astruct
106
109
  licenses: []
107
110
  post_install_message:
@@ -116,7 +119,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
119
  version: '0'
117
120
  segments:
118
121
  - 0
119
- hash: -3476508434562981874
122
+ hash: -2502922354495279839
120
123
  required_rubygems_version: !ruby/object:Gem::Requirement
121
124
  none: false
122
125
  requirements:
@@ -125,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
128
  version: '0'
126
129
  segments:
127
130
  - 0
128
- hash: -3476508434562981874
131
+ hash: -2502922354495279839
129
132
  requirements: []
130
133
  rubyforge_project:
131
134
  rubygems_version: 1.8.24
@@ -135,4 +138,5 @@ summary: An alternative to OpenStruct
135
138
  test_files:
136
139
  - test/helper.rb
137
140
  - test/lib/astruct_test.rb
141
+ - test/lib/ostruct_test.rb
138
142
  has_rdoc:
@@ -1,17 +0,0 @@
1
- require 'benchmark/ips'
2
- require_relative '../lib/astruct'
3
- require 'ostruct'
4
-
5
- DATA = (1..1_000).map { |i| { :"item#{i}" => i } }.inject :merge!
6
-
7
- Benchmark.ips do |x|
8
- x.report "OStruct creation" do
9
- class OProfile < OpenStruct; end
10
- OProfile.new DATA.dup
11
- end
12
-
13
- x.report "AStruct creation" do
14
- class AProfile < AltStruct; end
15
- AProfile.new DATA.dup
16
- end
17
- end
@@ -1,34 +0,0 @@
1
- require 'benchmark/ips'
2
- require_relative '../lib/astruct'
3
- require 'ostruct'
4
-
5
- DATA = (1..1_000).map { |i| { :"item#{i}" => i } }.inject :merge!
6
-
7
- Benchmark.ips do |x|
8
- x.report "OStruct load" do
9
- class OProfile < OpenStruct; end
10
- op = OProfile.new DATA.dup
11
- op.op2 = OProfile.new DATA.dup
12
- op.op2.op3 = OProfile.new DATA.dup
13
- op.inspect
14
- end
15
-
16
- x.report "AStruct load" do
17
- class AProfile < AltStruct; end
18
- ap = AProfile.new DATA.dup
19
- ap.ap2 = AProfile.new DATA.dup
20
- ap.ap2.ap3 = AProfile.new DATA.dup
21
- ap.inspect
22
- end
23
- end
24
-
25
- op = OProfile.new DATA.dup
26
- op.op2 = OProfile.new DATA.dup
27
- op.op2.op3 = OProfile.new DATA.dup
28
- ap = AProfile.new DATA.dup
29
- ap.ap2 = AProfile.new DATA.dup
30
- ap.ap2.ap3 = AProfile.new DATA.dup
31
- p ap.inspect
32
- p op.inspect
33
- puts "The output of each is the same: #{ap.inspect == op.inspect}"
34
-
@@ -1,19 +0,0 @@
1
- require 'benchmark/ips'
2
- require_relative '../lib/astruct'
3
- require 'ostruct'
4
-
5
- DATA = (1..1_000).map { |i| { :"item#{i}" => i } }.inject :merge!
6
-
7
- Benchmark.ips do |x|
8
- x.report "OStruct load" do
9
- class OProfile < OpenStruct; end
10
- op = OProfile.new DATA.dup
11
- op.delete_field :item1
12
- end
13
-
14
- x.report "AStruct load" do
15
- class AProfile < AltStruct; end
16
- ap = AProfile.new DATA.dup
17
- ap.delete :item1
18
- end
19
- end
@@ -1,25 +0,0 @@
1
- require 'benchmark/ips'
2
- require_relative '../lib/astruct'
3
- require 'ostruct'
4
-
5
- DATA = (1..1_000).map { |i| { :"item#{i}" => i } }.inject :merge!
6
-
7
- Benchmark.ips do |x|
8
- x.report "OStruct load" do
9
- class OProfile < OpenStruct; end
10
- op = OProfile.new DATA.dup
11
- op.marshal_dump
12
- end
13
-
14
- x.report "AStruct load" do
15
- class AProfile < AltStruct; end
16
- ap = AProfile.new DATA.dup
17
- ap.dump
18
- end
19
- end
20
-
21
- class OProfile < OpenStruct; end
22
- op = OProfile.new DATA.dup
23
- class AProfile < AltStruct; end
24
- ap = AProfile.new DATA.dup
25
- puts "The output of each is the same: #{ap.dump == op.marshal_dump}"
@@ -1,23 +0,0 @@
1
- require 'benchmark/ips'
2
- require_relative '../lib/astruct'
3
- require 'ostruct'
4
-
5
- DATA = (1..1_000).map { |i| { :"item#{i}" => i } }.inject :merge!
6
-
7
- Benchmark.ips do |x|
8
- x.report "OStruct creation" do
9
- class OProfile < OpenStruct; end
10
- op = OProfile.new DATA.dup
11
- op.example1 = "red"
12
- op.example2 = "blue"
13
- op.example3 = "green"
14
- end
15
-
16
- x.report "AStruct creation" do
17
- class AProfile < AltStruct; end
18
- ap = AProfile.new DATA.dup
19
- ap.example1 = "red"
20
- ap.example2 = "blue"
21
- ap.example3 = "green"
22
- end
23
- end
@@ -1,19 +0,0 @@
1
- require 'benchmark/ips'
2
- require_relative '../lib/astruct'
3
- require 'ostruct'
4
-
5
- DATA = (1..1_000).map { |i| { :"item#{i}" => i } }.inject :merge!
6
-
7
- Benchmark.ips do |x|
8
- x.report "OStruct load" do
9
- class OProfile < OpenStruct; end
10
- op = OProfile.new DATA.dup
11
- op.inspect
12
- end
13
-
14
- x.report "AStruct load" do
15
- class AProfile < AltStruct; end
16
- ap = AProfile.new DATA.dup
17
- ap.inspect
18
- end
19
- end
@@ -1,19 +0,0 @@
1
- require 'benchmark/ips'
2
- require_relative '../lib/astruct'
3
- require 'ostruct'
4
-
5
- DATA = (1..1_000).map { |i| { :"item#{i}" => i } }.inject :merge!
6
-
7
- Benchmark.ips do |x|
8
- x.report "OStruct load" do
9
- class OProfile < OpenStruct; end
10
- op = OProfile.new
11
- op.marshal_load DATA.dup
12
- end
13
-
14
- x.report "AStruct load" do
15
- class AProfile < AltStruct; end
16
- ap = AProfile.new
17
- ap.load DATA.dup
18
- end
19
- end