-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbenchmark_attributed_object.rb
108 lines (97 loc) · 2.53 KB
/
benchmark_attributed_object.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
require 'benchmark'
# require 'virtus'
# require 'dry/types'
require 'attributed_object'
# class VirtusValue
# include Virtus.value_object
#
# values do
# attribute :id, Integer
# attribute :claimed, Boolean
# attribute :pro_coach, Boolean
# attribute :url, String
# end
# end
#
# class VirtusModel
# include Virtus.model(:strict => true)
#
# attribute :id, Integer
# attribute :claimed, Boolean
# attribute :pro_coach, Boolean
# attribute :url, String
# end
#
class AttrObj
include AttributedObject::Strict
attribute :id, :integer, disallow: nil
attribute :claimed, :boolean, disallow: nil
attribute :pro_coach, :boolean, disallow: nil
attribute :url, :string, disallow: nil
end
class AttrObjCoerce
include AttributedObject::Coerce
attribute :id, :integer, disallow: nil
attribute :claimed, :boolean, disallow: nil
attribute :pro_coach, :boolean, disallow: nil
attribute :url, :string, disallow: nil
end
#
# class DryValue < Dry::Types::Value
# attribute :id, 'strict.int'
# attribute :claimed, "strict.bool"
# attribute :pro_coach, "strict.bool"
# attribute :url, "strict.string"
# end
class Poro
attr_reader :id
attr_reader :claimed
attr_reader :pro_coach
attr_reader :url
def initialize(id:, claimed:, pro_coach:, url:)
@id = id
@claimed = claimed
@pro_coach = pro_coach
@url = url
end
end
iterations = 10_000
Benchmark.bm(27) do |bm|
# bm.report('Virtus Value') do
# iterations.times do
# VirtusValue.new(id: 1, claimed: true, pro_coach: true, url: 'http://google.de')
# end
# end
#
# bm.report('DryValue') do
# iterations.times do
# DryValue.new(id: 1, claimed: true, pro_coach: true, url: 'http://google.de')
# end
# end
#
# bm.report('Virtus Model') do
# iterations.times do
# VirtusModel.new(id: 1, claimed: true, pro_coach: true, url: 'http://google.de')
# end
# end
bm.report('AttributedObject') do
iterations.times do
AttrObj.new(id: 1, claimed: true, pro_coach: true, url: 'http://google.de')
end
end
bm.report('AttributedObjectCoerce Match') do
iterations.times do
AttrObjCoerce.new(id: 1, claimed: true, pro_coach: true, url: 'http://google.de')
end
end
bm.report('AttributedObjectCoerce All Strings') do
iterations.times do
AttrObjCoerce.new(id: '1', claimed: '1', pro_coach: 'true', url: 'http://google.de')
end
end
bm.report('Poro') do
iterations.times do
Poro.new(id: 1, claimed: true, pro_coach: true, url: 'http://google.de')
end
end
end