Forked from palexander/ruby_data_object_comparison.rb
Last active
September 17, 2020 12:24
-
-
Save skatkov/c32ffff81dc22e2e955533e4591b335c to your computer and use it in GitHub Desktop.
Revisions
-
Stanislav (Stas) Katkov revised this gist
Sep 17, 2020 . 1 changed file with 13 additions and 15 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 @@ -6,7 +6,10 @@ EMAIL = "[email protected]" class Person def initialize(name:, email:) @name = name @email = email end end Benchmark.bm(13) do |x| @@ -18,32 +21,27 @@ class Person x.report("openstruct:") do COUNT.times do OpenStruct.new(name: NAME, email: EMAIL) end end x.report("struct:") do PersonStruct = Struct.new(:name, :email) COUNT.times do PersonStruct.new(name: NAME, email: EMAIL) end end x.report("class:") do COUNT.times do Person.new(name: NAME, email: EMAIL) end end end user system total real hash: 1.310324 0.000000 1.310324 ( 1.313880) openstruct: 6.497740 0.002865 6.500605 ( 6.514609) struct: 3.147043 0.000004 3.147047 ( 3.154298) class: 5.571384 0.000000 5.571384 ( 5.583647) -
palexander revised this gist
Jan 24, 2014 . 1 changed file with 7 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 @@ -40,4 +40,10 @@ class Person p.email = EMAIL end end end user system total real hash: 4.610000 0.250000 4.860000 ( 4.857328) openstruct: 134.900000 2.830000 137.730000 (137.811739) struct: 3.940000 0.000000 3.940000 ( 3.943897) class: 2.480000 0.000000 2.480000 ( 2.486405) -
palexander created this gist
Jan 24, 2014 .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,43 @@ require 'ostruct' require 'benchmark' COUNT = 10_000_000 NAME = "Test Name" EMAIL = "[email protected]" class Person attr_accessor :name, :email end Benchmark.bm(13) do |x| x.report("hash:") do COUNT.times do p = {name: NAME, email: EMAIL} end end x.report("openstruct:") do COUNT.times do p = OpenStruct.new p.name = NAME p.email = EMAIL end end x.report("struct:") do PersonStruct = Struct.new(:name, :email) COUNT.times do p = PersonStruct.new p.name = NAME p.email = EMAIL end end x.report("class:") do COUNT.times do p = Person.new p.name = NAME p.email = EMAIL end end end