Last active June 19, 2023 22:37
-
-
Save pcreux/63a76bf36fc13525fc49bba191d4a88c to your computer and use it in GitHub Desktop.
Revisions
-
pcreux renamed this gist
Nov 15, 2021 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
pcreux revised this gist
Nov 15, 2021 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -32,6 +32,6 @@ module Types end Benchmark.memory do |x| x.report("ActiveModel") { AMUser.new(attributes) } x.report("DryStruct") { DryUser.new(attributes) } end -
pcreux revised this gist
Nov 15, 2021 . 2 changed files with 16 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,7 @@ require 'active_model' require 'dry-struct' require 'benchmark/ips' require 'benchmark/memory' class AMUser include ActiveModel::Model @@ -28,4 +29,9 @@ module Types Benchmark.ips do |x| x.report("ActiveModel") { AMUser.new(attributes) } x.report("DryStruct") { DryUser.new(attributes) } end Benchmark.memory do |x| x.report("ActiveModel") { 1000.times { AMUser.new(attributes) } } x.report("DryStruct") { 1000.times { DryUser.new(attributes) }} end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,4 +3,13 @@ Warming up -------------------------------------- DryStruct 26.361k i/100ms Calculating ------------------------------------- ActiveModel 106.109k (± 6.9%) i/s - 539.231k in 5.107054s DryStruct 362.653k (± 6.4%) i/s - 1.819M in 5.040403s Calculating ------------------------------------- ActiveModel 1,192 memsize ( 0.000 retained) 20 objects ( 0.000 retained) 8 strings ( 0.000 retained) DryStruct 208 memsize ( 0.000 retained) 2 objects ( 0.000 retained) 0 strings ( 0.000 retained) -
pcreux created this gist
Nov 15, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ require 'active_model' require 'dry-struct' require 'benchmark/ips' class AMUser include ActiveModel::Model include ActiveModel::Attributes attribute :id, :integer attribute :name, :string attribute :birthday, :date attribute :last_logged_in_at, :datetime end class DryUser < Dry::Struct module Types include Dry::Types() end attribute :id, Types::Integer attribute :name, Types::String attribute :birthday, Types::Date attribute :last_logged_in_at, Types::Time end attributes = { id: 1, name: "Yuki", birthday: Date.new(1987, 12, 30), last_logged_in_at: Time.now } Benchmark.ips do |x| x.report("ActiveModel") { AMUser.new(attributes) } x.report("DryStruct") { DryUser.new(attributes) } end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ Warming up -------------------------------------- ActiveModel 11.473k i/100ms DryStruct 26.361k i/100ms Calculating ------------------------------------- ActiveModel 106.109k (± 6.9%) i/s - 539.231k in 5.107054s DryStruct 362.653k (± 6.4%) i/s - 1.819M in 5.040403s