fast_ostruct 1.0.0.pre.beta.1 → 1.0.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9502e2ecb7219a23128b6d4991c3e6c8c6aed3d4366630e997089acda781a1cd
4
- data.tar.gz: 7c201bcf3996841ad07e2ae569f06d2d36620fd997cb0f67782dfcd9dc1cf720
3
+ metadata.gz: 8e01f31074bbe28459762b9c683d411b6449a1e4ae5e229bcfb6b31f47d5c462
4
+ data.tar.gz: 17871acbf4b3d78aad9e170e2029820a232ef266ad077f0f525a36b77724bbd0
5
5
  SHA512:
6
- metadata.gz: 178354cbf080dda94623c737de76dd4f4c1836e561995ba775febcdace89a1e1c2297a0f5c625f3d975c1720f5ded22e675487f7793d7b44ea725400251978b9
7
- data.tar.gz: 7aa334c603be1cf95e39ca12bf26285f503e359c1be2ecf9dcad67889ce52e48f59cfd1d7245e4958774bb20337cb4d8f3591a80ccb971c9d6234380e5fd84da
6
+ metadata.gz: 6657426960492212688eb4976f0f81ab6404bb6e078d29c6b9eebe7fdbcbfe8299572f869b8df8b7dad2796b7e607a3989d12f240bb4ff82764d34e2e18a0e2d
7
+ data.tar.gz: 21564c9d519e0d53faaf5b0e7b136e43fafc8364da2e1828dd7809b8325fe86ae2169a3ee5cfa575a44299f23c4eb7429d4c20b475d9bce4ae00bc83031813c9
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Fast OpenStruct
2
2
 
3
+ [![FastOpenStruct CI](https://github.com/w-osilva/fast_ostruct/actions/workflows/fast-ostruct_ci.yml/badge.svg)](https://github.com/w-osilva/fast_ostruct/actions/workflows/fast-ostruct_ci.yml)
4
+ [![Gem Version](https://badge.fury.io/rb/fast_ostruct.svg)](https://badge.fury.io/rb/fast_ostruct)
5
+
3
6
  It was inspirated on [DynamicClass](https://github.com/amcaplan/dynamic_class) gem.
4
7
 
5
8
  The main purpose of this gem is behave like an OpenStruct, but with some extra powers.
@@ -58,60 +61,61 @@ my_struct.dig(:age) # => 30
58
61
  Initialization benchmark
59
62
 
60
63
  Warming up --------------------------------------
61
- OpenStruct 15.041k i/100ms
62
- FastOpenStruct 116.264k i/100ms
64
+ OpenStruct 6.967k i/100ms
65
+ FastOpenStruct 45.819k i/100ms
63
66
  Calculating -------------------------------------
64
- OpenStruct 152.606k2.4%) i/s - 767.091k in 5.029398s
65
- FastOpenStruct 1.148M (± 1.4%) i/s - 5.813M in 5.063585s
67
+ OpenStruct 70.614k4.4%) i/s - 355.317k in 5.042038s
68
+ FastOpenStruct 454.480k (± 1.6%) i/s - 2.291M in 5.042112s
66
69
 
67
70
  Comparison:
68
- FastOpenStruct: 1148278.4 i/s
69
- OpenStruct: 152606.3 i/s - 7.52x slower
71
+ FastOpenStruct: 454479.6 i/s
72
+ OpenStruct: 70614.1 i/s - 6.44x slower
70
73
 
71
74
 
72
75
 
73
76
  Assignment Benchmark
74
77
 
75
78
  Warming up --------------------------------------
76
- OpenStruct 682.010k i/100ms
77
- FastOpenStruct 1.972M i/100ms
79
+ OpenStruct 317.626k i/100ms
80
+ FastOpenStruct 1.413M i/100ms
78
81
  Calculating -------------------------------------
79
- OpenStruct 6.980M3.3%) i/s - 35.465M in 5.086554s
80
- FastOpenStruct 19.964M (± 0.8%) i/s - 100.582M in 5.038516s
82
+ OpenStruct 3.222M0.3%) i/s - 16.199M in 5.027118s
83
+ FastOpenStruct 14.663M1.0%) i/s - 73.465M in 5.010767s
81
84
 
82
85
  Comparison:
83
- FastOpenStruct: 19964034.5 i/s
84
- OpenStruct: 6980499.3 i/s - 2.86x slower
86
+ FastOpenStruct: 14662985.4 i/s
87
+ OpenStruct: 3222330.4 i/s - 4.55x slower
85
88
 
86
89
 
87
90
 
88
91
  Access Benchmark
89
92
 
90
93
  Warming up --------------------------------------
91
- OpenStruct 1.005M i/100ms
92
- FastOpenStruct 2.185M i/100ms
94
+ OpenStruct 455.965k i/100ms
95
+ FastOpenStruct 1.511M i/100ms
93
96
  Calculating -------------------------------------
94
- OpenStruct 10.085M0.5%) i/s - 51.245M in 5.081712s
95
- FastOpenStruct 21.798M1.1%) i/s - 109.268M in 5.013290s
97
+ OpenStruct 4.533M3.2%) i/s - 22.798M in 5.034950s
98
+ FastOpenStruct 15.154M0.5%) i/s - 77.063M in 5.085386s
96
99
 
97
100
  Comparison:
98
- FastOpenStruct: 21798290.7 i/s
99
- OpenStruct: 10084528.1 i/s - 2.16x slower
101
+ FastOpenStruct: 15154237.8 i/s
102
+ OpenStruct: 4533257.4 i/s - 3.34x slower
100
103
 
101
104
 
102
105
 
103
106
  All-Together Benchmark
104
107
 
105
108
  Warming up --------------------------------------
106
- OpenStruct 12.918k i/100ms
107
- FastOpenStruct 111.460k i/100ms
109
+ OpenStruct 5.084k i/100ms
110
+ FastOpenStruct 218.702k i/100ms
108
111
  Calculating -------------------------------------
109
- OpenStruct 127.875k2.7%) i/s - 645.900k in 5.054749s
110
- FastOpenStruct 1.122M1.1%) i/s - 5.684M in 5.066350s
112
+ OpenStruct 52.705k4.7%) i/s - 264.368k in 5.027437s
113
+ FastOpenStruct 2.135M4.1%) i/s - 10.716M in 5.028416s
111
114
 
112
115
  Comparison:
113
- FastOpenStruct: 1122147.0 i/s
114
- OpenStruct: 127874.6 i/s - 8.78x slower
116
+ FastOpenStruct: 2135322.0 i/s
117
+ OpenStruct: 52704.7 i/s - 40.51x slower
118
+
115
119
  ```
116
120
 
117
121
  ## Contributing
data/lib/fast_ostruct.rb CHANGED
@@ -4,7 +4,7 @@ require 'json'
4
4
  require 'set'
5
5
 
6
6
  class FastOpenStruct
7
- VERSION = '1.0.0-beta.1'
7
+ VERSION = '1.0.1'
8
8
 
9
9
  INITIALIZE_OPTIONS = { deep_initialize: true }.freeze
10
10
  ATTRIBUTES_OPTIONS = { symbolize_keys: false }.freeze
@@ -41,12 +41,12 @@ class FastOpenStruct
41
41
  end
42
42
 
43
43
  def to_json(*_args)
44
- attributes.to_json
44
+ JSON.generate(attributes)
45
45
  end
46
46
  alias serializable_hash attributes
47
47
  alias to_h attributes
48
48
 
49
- # Accessible
49
+ # Hasheable
50
50
  def [](name)
51
51
  attribute_get(name)
52
52
  end
@@ -104,10 +104,10 @@ class FastOpenStruct
104
104
  @defined_methods ||= Set.new
105
105
  end
106
106
 
107
- def define_method!(name)
107
+ def define_methods!(name)
108
108
  class_exec do
109
- attr_writer name unless method_defined?("#{name}=")
110
- attr_reader name unless method_defined?(name)
109
+ attr_accessor name
110
+
111
111
  defined_methods << name
112
112
  end
113
113
  end
@@ -126,16 +126,16 @@ class FastOpenStruct
126
126
  return if name.nil?
127
127
 
128
128
  name = name.to_sym
129
- self.class.define_method!(name) unless self.class.defined_methods.include?(name)
130
- instance_variable_set("@#{name}", value)
129
+ self.class.define_methods!(name) unless self.class.defined_methods.include?(name)
130
+ instance_variable_set(:"@#{name}", value)
131
131
  end
132
132
 
133
133
  def attribute_get(name)
134
- instance_variable_get("@#{name}")
134
+ instance_variable_get(:"@#{name}")
135
135
  end
136
136
 
137
137
  def attribute_unset(name)
138
- remove_instance_variable("@#{name}")
138
+ remove_instance_variable(:"@#{name}")
139
139
  end
140
140
 
141
141
  def method_missing(mid, *args)
@@ -10,7 +10,7 @@ namespace :fast_open_struct do
10
10
  task :benchmark do
11
11
  puts "Initialization benchmark\n\n"
12
12
  Benchmark.ips do |x|
13
- input_hash = { foo: :bar }
13
+ input_hash = { foo: :bar, bar: :baz, baz: :foo }
14
14
 
15
15
  x.report('OpenStruct') do
16
16
  OpenStruct.new(input_hash)
@@ -23,47 +23,60 @@ namespace :fast_open_struct do
23
23
 
24
24
  puts "\n\nAssignment Benchmark\n\n"
25
25
  Benchmark.ips do |x|
26
- input_hash = { foo: :bar }
27
- os = OpenStruct.new(input_hash)
28
- fos = FastOpenStruct.new(input_hash)
26
+ os = OpenStruct.new
27
+ fos = FastOpenStruct.new
29
28
 
30
29
  x.report('OpenStruct') do
31
30
  os.foo = :bar
31
+ os.bar = :baz
32
+ os.baz = :foo
32
33
  end
33
34
  x.report('FastOpenStruct') do
34
35
  fos.foo = :bar
36
+ fos.bar = :baz
37
+ fos.baz = :foo
35
38
  end
36
39
  x.compare!
37
40
  end
38
41
 
39
42
  puts "\n\nAccess Benchmark\n\n"
40
43
  Benchmark.ips do |x|
41
- input_hash = { foo: :bar }
44
+ input_hash = { foo: :bar, bar: :baz, baz: :foo }
42
45
  os = OpenStruct.new(input_hash)
43
46
  fos = FastOpenStruct.new(input_hash)
44
47
 
45
48
  x.report('OpenStruct') do
46
49
  os.foo
50
+ os.bar
51
+ os.baz
47
52
  end
48
53
  x.report('FastOpenStruct') do
49
54
  fos.foo
55
+ fos.bar
56
+ fos.baz
50
57
  end
51
58
  x.compare!
52
59
  end
53
60
 
54
61
  puts "\n\nAll-Together Benchmark\n\n"
55
62
  Benchmark.ips do |x|
56
- input_hash = { foo: :bar }
57
-
58
63
  x.report('OpenStruct') do
59
- os = OpenStruct.new(input_hash)
64
+ os = OpenStruct.new
60
65
  os.foo = :bar
61
66
  os.foo
67
+ os.bar = :baz
68
+ os.bar
69
+ os.baz = :foo
70
+ os.baz
62
71
  end
63
72
  x.report('FastOpenStruct') do
64
- fos = FastOpenStruct.new(input_hash)
73
+ fos = FastOpenStruct.new
65
74
  fos.foo = :bar
66
75
  fos.foo
76
+ fos.bar = :baz
77
+ fos.bar
78
+ fos.baz = :foo
79
+ fos.baz
67
80
  end
68
81
  x.compare!
69
82
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_ostruct
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.beta.1
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Washington Silva
@@ -162,9 +162,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
162
162
  version: '3.0'
163
163
  required_rubygems_version: !ruby/object:Gem::Requirement
164
164
  requirements:
165
- - - ">"
165
+ - - ">="
166
166
  - !ruby/object:Gem::Version
167
- version: 1.3.1
167
+ version: '0'
168
168
  requirements: []
169
169
  rubygems_version: 3.1.6
170
170
  signing_key: