fast_ostruct 1.0.0.pre.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/fast-ostruct_ci.yml +53 -0
- data/.gitignore +16 -0
- data/.rspec +3 -0
- data/.rubocop.yml +68 -0
- data/.ruby-version +1 -0
- data/Gemfile +6 -0
- data/LICENSE +21 -0
- data/README.md +123 -0
- data/Rakefile +13 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/fast_ostruct.gemspec +38 -0
- data/lib/fast_ostruct.rb +152 -0
- data/lib/tasks/benchmark.rake +72 -0
- metadata +173 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ed10c73a7bbd13261e7ceee225cae1b1a38d92cbdd43a6be2a8e95f061659830
|
4
|
+
data.tar.gz: 0c8a054cddf3955944c5763944f424e2eb16536ca3d7cb76c5efefea868bb376
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 18d94168b2f35b5f49856686b8df0f8e33a434f68380e467b063a69287d8fb1822af47247c6fb59cd607feaebbef4c38a3fe526b07bf5a6a776e2cd4ead06c7f
|
7
|
+
data.tar.gz: e1413fbd90c3968118d6613e5ac6dd96efd74adf5081158a330d03df628b6dcd91a9942ad01328a402c58920b27975c06917a31b2bb51b5424922e7894e7f7b4
|
@@ -0,0 +1,53 @@
|
|
1
|
+
name: FastOpenStruct CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ "main" ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ "main" ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v3
|
14
|
+
- name: Set up Ruby
|
15
|
+
uses: ruby/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
bundler-cache: true
|
18
|
+
- name: Run specs
|
19
|
+
run: bundle exec rspec --format progress
|
20
|
+
|
21
|
+
publish:
|
22
|
+
needs: [test]
|
23
|
+
# if: github.ref == 'refs/heads/main'
|
24
|
+
runs-on: ubuntu-latest
|
25
|
+
steps:
|
26
|
+
- uses: actions/checkout@v3
|
27
|
+
- name: Set up Ruby
|
28
|
+
uses: ruby/setup-ruby@v1
|
29
|
+
with:
|
30
|
+
ruby-version: 2.7.8
|
31
|
+
|
32
|
+
- name: Publish to GitHub Packages Registry
|
33
|
+
run: |
|
34
|
+
mkdir -p $HOME/.gem
|
35
|
+
touch $HOME/.gem/credentials
|
36
|
+
chmod 0600 $HOME/.gem/credentials
|
37
|
+
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
38
|
+
gem build *.gemspec
|
39
|
+
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
|
40
|
+
env:
|
41
|
+
GEM_HOST_API_KEY: "Bearer ${{secrets.PACKAGES_TOKEN}}"
|
42
|
+
OWNER: ${{ github.repository_owner }}
|
43
|
+
|
44
|
+
- name: Publish to RubyGems
|
45
|
+
run: |
|
46
|
+
mkdir -p $HOME/.gem
|
47
|
+
touch $HOME/.gem/credentials
|
48
|
+
chmod 0600 $HOME/.gem/credentials
|
49
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
50
|
+
gem build *.gemspec
|
51
|
+
gem push *.gem
|
52
|
+
env:
|
53
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require: rubocop-performance
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
NewCops: enable
|
5
|
+
Exclude:
|
6
|
+
- 'spec/fixtures/**/*'
|
7
|
+
- '.git/**/*'
|
8
|
+
TargetRubyVersion: 3.0
|
9
|
+
SuggestExtensions: false
|
10
|
+
|
11
|
+
Style/FormatStringToken:
|
12
|
+
Exclude:
|
13
|
+
- spec/**/*
|
14
|
+
|
15
|
+
Style/Documentation:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Style/HashSyntax:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Layout/EndOfLine:
|
22
|
+
EnforcedStyle: lf
|
23
|
+
|
24
|
+
Layout/ClassStructure:
|
25
|
+
Enabled: true
|
26
|
+
Categories:
|
27
|
+
module_inclusion:
|
28
|
+
- include
|
29
|
+
- prepend
|
30
|
+
- extend
|
31
|
+
ExpectedOrder:
|
32
|
+
- module_inclusion
|
33
|
+
- constants
|
34
|
+
- public_class_methods
|
35
|
+
- initializer
|
36
|
+
- instance_methods
|
37
|
+
- protected_methods
|
38
|
+
- private_methods
|
39
|
+
|
40
|
+
# Trailing white space is meaningful in code examples
|
41
|
+
Layout/TrailingWhitespace:
|
42
|
+
AllowInHeredoc: true
|
43
|
+
|
44
|
+
Lint/AmbiguousBlockAssociation:
|
45
|
+
Exclude:
|
46
|
+
- 'spec/**/*.rb'
|
47
|
+
|
48
|
+
Layout/LineLength:
|
49
|
+
Max: 120
|
50
|
+
AllowedPatterns:
|
51
|
+
- !ruby/regexp /\A +(it|describe|context|shared_examples|include_examples|it_behaves_like) ["']/
|
52
|
+
|
53
|
+
Metrics/BlockLength:
|
54
|
+
Exclude:
|
55
|
+
- 'Rakefile'
|
56
|
+
- '**/*.rake'
|
57
|
+
- 'spec/**/*.rb'
|
58
|
+
- '**/*.gemspec'
|
59
|
+
|
60
|
+
Metrics/ModuleLength:
|
61
|
+
Exclude:
|
62
|
+
- 'spec/**/*.rb'
|
63
|
+
|
64
|
+
Metrics/ClassLength:
|
65
|
+
Max: 150
|
66
|
+
|
67
|
+
Metrics/MethodLength:
|
68
|
+
Max: 15
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.1.2
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023 Washington Silva
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
# Fast OpenStruct
|
2
|
+
|
3
|
+
It was inspirated on [DynamicClass](https://github.com/amcaplan/dynamic_class) gem.
|
4
|
+
|
5
|
+
The main purpose of this gem is behave like an OpenStruct, but with some extra powers.
|
6
|
+
|
7
|
+
The main difference for OpenStruct is that this implementation has a cache of the methods that are created, so it is faster.
|
8
|
+
|
9
|
+
## Diferences from OpenStruct
|
10
|
+
|
11
|
+
- It is faster
|
12
|
+
- It has a cache of the methods that are created
|
13
|
+
- It does not uses @table instance variable
|
14
|
+
- It has a dig method that works like Hash#dig to access nested attributes
|
15
|
+
- It implements some methods of **ActiveModel::API** and **ActiveModel::Serialization**, making it useful for some cases (i.e. using it as :class for FactoryBot factories)
|
16
|
+
- It makes a deep initialization of the attributes, converting Hash to FastOpenStruct
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
Add this line to your application's Gemfile:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
gem 'fast_ostruct'
|
24
|
+
```
|
25
|
+
|
26
|
+
And then execute:
|
27
|
+
|
28
|
+
$ bundle
|
29
|
+
|
30
|
+
Or install it yourself as:
|
31
|
+
|
32
|
+
$ gem install fast_ostruct
|
33
|
+
|
34
|
+
|
35
|
+
## Usage
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
require 'fast_ostruct'
|
39
|
+
|
40
|
+
attributes = { name: 'John' }
|
41
|
+
|
42
|
+
my_struct = FastOpenStruct.new(attributes)
|
43
|
+
|
44
|
+
# Set attributes
|
45
|
+
my_struct.nickname = 'Big John'
|
46
|
+
my_struct['lastname'] = 'Connor'
|
47
|
+
my_struct[:age] = 30
|
48
|
+
|
49
|
+
# Access attributes
|
50
|
+
my_struct.name # => 'John'
|
51
|
+
my_struct[:nickname] # => 'Big John'
|
52
|
+
my_struct['lastname'] # => 'Connor'
|
53
|
+
my_struct.dig(:age) # => 30
|
54
|
+
```
|
55
|
+
|
56
|
+
## Benchmarks
|
57
|
+
```
|
58
|
+
Initialization benchmark
|
59
|
+
|
60
|
+
Warming up --------------------------------------
|
61
|
+
OpenStruct 15.041k i/100ms
|
62
|
+
FastOpenStruct 116.264k i/100ms
|
63
|
+
Calculating -------------------------------------
|
64
|
+
OpenStruct 152.606k (± 2.4%) i/s - 767.091k in 5.029398s
|
65
|
+
FastOpenStruct 1.148M (± 1.4%) i/s - 5.813M in 5.063585s
|
66
|
+
|
67
|
+
Comparison:
|
68
|
+
FastOpenStruct: 1148278.4 i/s
|
69
|
+
OpenStruct: 152606.3 i/s - 7.52x slower
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
Assignment Benchmark
|
74
|
+
|
75
|
+
Warming up --------------------------------------
|
76
|
+
OpenStruct 682.010k i/100ms
|
77
|
+
FastOpenStruct 1.972M i/100ms
|
78
|
+
Calculating -------------------------------------
|
79
|
+
OpenStruct 6.980M (± 3.3%) i/s - 35.465M in 5.086554s
|
80
|
+
FastOpenStruct 19.964M (± 0.8%) i/s - 100.582M in 5.038516s
|
81
|
+
|
82
|
+
Comparison:
|
83
|
+
FastOpenStruct: 19964034.5 i/s
|
84
|
+
OpenStruct: 6980499.3 i/s - 2.86x slower
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
Access Benchmark
|
89
|
+
|
90
|
+
Warming up --------------------------------------
|
91
|
+
OpenStruct 1.005M i/100ms
|
92
|
+
FastOpenStruct 2.185M i/100ms
|
93
|
+
Calculating -------------------------------------
|
94
|
+
OpenStruct 10.085M (± 0.5%) i/s - 51.245M in 5.081712s
|
95
|
+
FastOpenStruct 21.798M (± 1.1%) i/s - 109.268M in 5.013290s
|
96
|
+
|
97
|
+
Comparison:
|
98
|
+
FastOpenStruct: 21798290.7 i/s
|
99
|
+
OpenStruct: 10084528.1 i/s - 2.16x slower
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
All-Together Benchmark
|
104
|
+
|
105
|
+
Warming up --------------------------------------
|
106
|
+
OpenStruct 12.918k i/100ms
|
107
|
+
FastOpenStruct 111.460k i/100ms
|
108
|
+
Calculating -------------------------------------
|
109
|
+
OpenStruct 127.875k (± 2.7%) i/s - 645.900k in 5.054749s
|
110
|
+
FastOpenStruct 1.122M (± 1.1%) i/s - 5.684M in 5.066350s
|
111
|
+
|
112
|
+
Comparison:
|
113
|
+
FastOpenStruct: 1122147.0 i/s
|
114
|
+
OpenStruct: 127874.6 i/s - 8.78x slower
|
115
|
+
```
|
116
|
+
|
117
|
+
## Contributing
|
118
|
+
|
119
|
+
Bug reports and pull requests are welcome on GitHub
|
120
|
+
|
121
|
+
## License
|
122
|
+
|
123
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
require 'rubocop/rake_task'
|
9
|
+
RuboCop::RakeTask.new
|
10
|
+
|
11
|
+
Dir.glob('lib/tasks/*.rake').each { |r| import r }
|
12
|
+
|
13
|
+
task default: %i[spec rubocop]
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'fast_ostruct'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/fast_ostruct'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'fast_ostruct'
|
7
|
+
spec.version = FastOpenStruct::VERSION
|
8
|
+
spec.authors = ['Washington Silva']
|
9
|
+
spec.email = ['w-osilva@hotmail.com']
|
10
|
+
spec.homepage = 'https://github.com/w-osilva/fast_ostruct'
|
11
|
+
spec.summary = 'A fast open struct alternative'
|
12
|
+
spec.licenses = ['MIT']
|
13
|
+
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 3.0')
|
15
|
+
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
17
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
18
|
+
spec.metadata['github_repo'] = spec.homepage
|
19
|
+
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.require_paths = ['lib']
|
26
|
+
|
27
|
+
spec.add_development_dependency 'benchmark-ips', '>= 2'
|
28
|
+
spec.add_development_dependency 'pry', '>= 0.14'
|
29
|
+
spec.add_development_dependency 'rack-test', '~> 1.1'
|
30
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
31
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
32
|
+
spec.add_development_dependency 'rubocop', '~> 1.25'
|
33
|
+
spec.add_development_dependency 'rubocop-performance', '~> 1.15'
|
34
|
+
|
35
|
+
spec.add_dependency 'json', '>= 2'
|
36
|
+
|
37
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
38
|
+
end
|
data/lib/fast_ostruct.rb
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'set'
|
5
|
+
|
6
|
+
class FastOpenStruct
|
7
|
+
VERSION = '1.0.0-alpha.1'
|
8
|
+
|
9
|
+
INITIALIZE_OPTIONS = { deep_initialize: true }.freeze
|
10
|
+
ATTRIBUTES_OPTIONS = { symbolize_keys: false }.freeze
|
11
|
+
|
12
|
+
def initialize(attributes = {}, options = INITIALIZE_OPTIONS)
|
13
|
+
if options[:deep_initialize]
|
14
|
+
attributes.except(*options.keys).each_pair do |name, value|
|
15
|
+
self[name] = deep_initialize(value, options)
|
16
|
+
end
|
17
|
+
else
|
18
|
+
attributes.except(*options.keys).each_pair do |name, value|
|
19
|
+
self[name] = value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def attributes(options = ATTRIBUTES_OPTIONS)
|
25
|
+
key_formatter = if options[:symbolize_keys]
|
26
|
+
proc { |name| name.to_sym }
|
27
|
+
else
|
28
|
+
proc { |name| name.to_s }
|
29
|
+
end
|
30
|
+
|
31
|
+
instance_variables.each_with_object({}) do |var, hash|
|
32
|
+
name = var.to_s.delete('@')
|
33
|
+
value = attribute_get(name)
|
34
|
+
hash[key_formatter.call(name)] = value.is_a?(FastOpenStruct) ? value.attributes(options) : value
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Serializable
|
39
|
+
def as_json(*_args)
|
40
|
+
attributes
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_json(*_args)
|
44
|
+
attributes.to_json
|
45
|
+
end
|
46
|
+
alias serializable_hash attributes
|
47
|
+
alias to_h attributes
|
48
|
+
|
49
|
+
# Accessible
|
50
|
+
def [](name)
|
51
|
+
attribute_get(name)
|
52
|
+
end
|
53
|
+
|
54
|
+
def []=(name, value)
|
55
|
+
attribute_set(name, value)
|
56
|
+
end
|
57
|
+
|
58
|
+
def dig(name, *identifiers)
|
59
|
+
name = name.to_sym
|
60
|
+
identifiers.map!(&:to_sym) if identifiers.any?
|
61
|
+
attributes(symbolize_keys: true).dig(name, *identifiers)
|
62
|
+
end
|
63
|
+
|
64
|
+
def delete_field(name)
|
65
|
+
attribute_unset(name)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Comparable
|
69
|
+
def ==(other)
|
70
|
+
other.is_a?(self.class) && attributes == other.attributes
|
71
|
+
end
|
72
|
+
|
73
|
+
def eql?(other)
|
74
|
+
other.is_a?(self.class) && attributes.eql?(other.attributes)
|
75
|
+
end
|
76
|
+
|
77
|
+
# Persistent
|
78
|
+
def persisted?
|
79
|
+
false
|
80
|
+
end
|
81
|
+
|
82
|
+
def save
|
83
|
+
self
|
84
|
+
end
|
85
|
+
|
86
|
+
def new_record?
|
87
|
+
true
|
88
|
+
end
|
89
|
+
|
90
|
+
alias save! save
|
91
|
+
alias create save
|
92
|
+
alias create! save
|
93
|
+
alias update save
|
94
|
+
alias update! save
|
95
|
+
alias delete save
|
96
|
+
alias destroy save
|
97
|
+
alias destroy! save
|
98
|
+
alias reload save
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
class << self
|
103
|
+
def defined_methods
|
104
|
+
@defined_methods ||= Set.new
|
105
|
+
end
|
106
|
+
|
107
|
+
def define_method!(name)
|
108
|
+
class_exec do
|
109
|
+
attr_writer name unless method_defined?("#{name}=")
|
110
|
+
attr_reader name unless method_defined?(name)
|
111
|
+
defined_methods << name
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def deep_initialize(value, options = INITIALIZE_OPTIONS)
|
117
|
+
if value.is_a?(Array)
|
118
|
+
value = value.map { |v| v.is_a?(Hash) ? self.class.new(v, options) : v }
|
119
|
+
elsif value.is_a?(Hash)
|
120
|
+
value = self.class.new(value, options)
|
121
|
+
end
|
122
|
+
value
|
123
|
+
end
|
124
|
+
|
125
|
+
def attribute_set(name, value = nil)
|
126
|
+
return if name.nil?
|
127
|
+
|
128
|
+
name = name.to_sym
|
129
|
+
self.class.define_method!(name) unless self.class.defined_methods.include?(name)
|
130
|
+
instance_variable_set("@#{name}", value)
|
131
|
+
end
|
132
|
+
|
133
|
+
def attribute_get(name)
|
134
|
+
instance_variable_get("@#{name}")
|
135
|
+
end
|
136
|
+
|
137
|
+
def attribute_unset(name)
|
138
|
+
remove_instance_variable("@#{name}")
|
139
|
+
end
|
140
|
+
|
141
|
+
def method_missing(mid, *args)
|
142
|
+
if (mname = mid[/.*(?==\z)/m])
|
143
|
+
self[mname] = args.first
|
144
|
+
else
|
145
|
+
self[mid]
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def respond_to_missing?(*args)
|
150
|
+
super(*args)
|
151
|
+
end
|
152
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'benchmark/ips'
|
4
|
+
require 'fast_ostruct'
|
5
|
+
require 'ostruct'
|
6
|
+
|
7
|
+
# rubocop:disable Style/OpenStructUse
|
8
|
+
namespace :fast_open_struct do
|
9
|
+
desc 'Run Benchmarking Examples'
|
10
|
+
task :benchmark do
|
11
|
+
puts "Initialization benchmark\n\n"
|
12
|
+
Benchmark.ips do |x|
|
13
|
+
input_hash = { foo: :bar }
|
14
|
+
|
15
|
+
x.report('OpenStruct') do
|
16
|
+
OpenStruct.new(input_hash)
|
17
|
+
end
|
18
|
+
x.report('FastOpenStruct') do
|
19
|
+
FastOpenStruct.new(input_hash)
|
20
|
+
end
|
21
|
+
x.compare!
|
22
|
+
end
|
23
|
+
|
24
|
+
puts "\n\nAssignment Benchmark\n\n"
|
25
|
+
Benchmark.ips do |x|
|
26
|
+
input_hash = { foo: :bar }
|
27
|
+
os = OpenStruct.new(input_hash)
|
28
|
+
fos = FastOpenStruct.new(input_hash)
|
29
|
+
|
30
|
+
x.report('OpenStruct') do
|
31
|
+
os.foo = :bar
|
32
|
+
end
|
33
|
+
x.report('FastOpenStruct') do
|
34
|
+
fos.foo = :bar
|
35
|
+
end
|
36
|
+
x.compare!
|
37
|
+
end
|
38
|
+
|
39
|
+
puts "\n\nAccess Benchmark\n\n"
|
40
|
+
Benchmark.ips do |x|
|
41
|
+
input_hash = { foo: :bar }
|
42
|
+
os = OpenStruct.new(input_hash)
|
43
|
+
fos = FastOpenStruct.new(input_hash)
|
44
|
+
|
45
|
+
x.report('OpenStruct') do
|
46
|
+
os.foo
|
47
|
+
end
|
48
|
+
x.report('FastOpenStruct') do
|
49
|
+
fos.foo
|
50
|
+
end
|
51
|
+
x.compare!
|
52
|
+
end
|
53
|
+
|
54
|
+
puts "\n\nAll-Together Benchmark\n\n"
|
55
|
+
Benchmark.ips do |x|
|
56
|
+
input_hash = { foo: :bar }
|
57
|
+
|
58
|
+
x.report('OpenStruct') do
|
59
|
+
os = OpenStruct.new(input_hash)
|
60
|
+
os.foo = :bar
|
61
|
+
os.foo
|
62
|
+
end
|
63
|
+
x.report('FastOpenStruct') do
|
64
|
+
fos = FastOpenStruct.new(input_hash)
|
65
|
+
fos.foo = :bar
|
66
|
+
fos.foo
|
67
|
+
end
|
68
|
+
x.compare!
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
# rubocop:enable Style/OpenStructUse
|
metadata
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fast_ostruct
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.pre.alpha.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Washington Silva
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-04-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: benchmark-ips
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.14'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.14'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rack-test
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '13.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '13.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.25'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.25'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop-performance
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.15'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.15'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: json
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '2'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '2'
|
125
|
+
description:
|
126
|
+
email:
|
127
|
+
- w-osilva@hotmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".github/workflows/fast-ostruct_ci.yml"
|
133
|
+
- ".gitignore"
|
134
|
+
- ".rspec"
|
135
|
+
- ".rubocop.yml"
|
136
|
+
- ".ruby-version"
|
137
|
+
- Gemfile
|
138
|
+
- LICENSE
|
139
|
+
- README.md
|
140
|
+
- Rakefile
|
141
|
+
- bin/console
|
142
|
+
- bin/setup
|
143
|
+
- fast_ostruct.gemspec
|
144
|
+
- lib/fast_ostruct.rb
|
145
|
+
- lib/tasks/benchmark.rake
|
146
|
+
homepage: https://github.com/w-osilva/fast_ostruct
|
147
|
+
licenses:
|
148
|
+
- MIT
|
149
|
+
metadata:
|
150
|
+
homepage_uri: https://github.com/w-osilva/fast_ostruct
|
151
|
+
source_code_uri: https://github.com/w-osilva/fast_ostruct
|
152
|
+
github_repo: https://github.com/w-osilva/fast_ostruct
|
153
|
+
rubygems_mfa_required: 'true'
|
154
|
+
post_install_message:
|
155
|
+
rdoc_options: []
|
156
|
+
require_paths:
|
157
|
+
- lib
|
158
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '3.0'
|
163
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - ">"
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: 1.3.1
|
168
|
+
requirements: []
|
169
|
+
rubygems_version: 3.1.6
|
170
|
+
signing_key:
|
171
|
+
specification_version: 4
|
172
|
+
summary: A fast open struct alternative
|
173
|
+
test_files: []
|