Skip to content

Commit 319c4da

Browse files
committed
Add basic OpenStruct benchmarks
All of the benchmarks except for 100x reads show a performance improvement. If you are reading the data repeatedly, it's still much better to use Struct or Data. ``` $ benchmark-driver benchmarks/ostruct.yml Warming up -------------------------------------- new 7.047k i/s - 7.711k times in 1.094212s (141.90μs/i) attr_write_read 4.904k i/s - 4.910k times in 1.001289s (203.93μs/i) index_write_attr_read 6.346k i/s - 6.963k times in 1.097167s (157.57μs/i) null_reads 79.488k i/s - 85.250k times in 1.072495s (12.58μs/i) 10x_reads 6.651k i/s - 7.282k times in 1.094836s (150.35μs/i) 100x_reads 5.136k i/s - 5.150k times in 1.002780s (194.71μs/i) Calculating ------------------------------------- v0.6.0 local new 6.938k 33.067k i/s - 21.141k times in 3.047342s 0.639334s attr_write_read 4.886k 14.021k i/s - 14.711k times in 3.010686s 1.049232s index_write_attr_read 6.270k 20.225k i/s - 19.039k times in 3.036489s 0.941373s null_reads 78.351k 77.187k i/s - 238.462k times in 3.043491s 3.089414s 10x_reads 6.518k 13.306k i/s - 19.953k times in 3.061390s 1.499576s 100x_reads 4.454k 2.078k i/s - 15.407k times in 3.459125s 7.414447s Comparison: new local: 33067.2 i/s v0.6.0: 6937.5 i/s - 4.77x slower attr_write_read local: 14020.7 i/s v0.6.0: 4886.3 i/s - 2.87x slower index_write_attr_read local: 20224.7 i/s v0.6.0: 6270.1 i/s - 3.23x slower null_reads v0.6.0: 78351.5 i/s local: 77186.8 i/s - 1.02x slower 10x_reads local: 13305.8 i/s v0.6.0: 6517.6 i/s - 2.04x slower 100x_reads v0.6.0: 4454.0 i/s local: 2078.0 i/s - 2.14x slower ```
1 parent de7e246 commit 319c4da

File tree

1 file changed

+154
-0
lines changed

1 file changed

+154
-0
lines changed

benchmarks/ostruct.yml

+154
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
prelude: |
2+
# frozen_string_literal: true
3+
4+
require "ostruct"
5+
keys = (0..29).map { :"method_#{_1}" }
6+
input = keys.to_h { [_1, _1] }
7+
8+
benchmark:
9+
new: |
10+
OpenStruct.new(input)
11+
12+
attr_write_read: |
13+
ostruct = OpenStruct.new
14+
ostruct.method_0 = "foo"
15+
ostruct.method_1 = "bar"
16+
ostruct.method_2 = "baz"
17+
ostruct.method_3 = "quux"
18+
ostruct.method_4 = "foo"
19+
ostruct.method_5 = "bar"
20+
ostruct.method_6 = "baz"
21+
ostruct.method_7 = "quux"
22+
ostruct.method_8 = "quux"
23+
ostruct.method_9 = "quux"
24+
ostruct.method_10 = "foo"
25+
ostruct.method_11 = "bar"
26+
ostruct.method_12 = "baz"
27+
ostruct.method_13 = "quux"
28+
ostruct.method_14 = "foo"
29+
ostruct.method_15 = "bar"
30+
ostruct.method_16 = "baz"
31+
ostruct.method_17 = "quux"
32+
ostruct.method_18 = "quux"
33+
ostruct.method_19 = "quux"
34+
ostruct.method_20 = "foo"
35+
ostruct.method_21 = "bar"
36+
ostruct.method_22 = "baz"
37+
ostruct.method_23 = "quux"
38+
ostruct.method_24 = "foo"
39+
ostruct.method_25 = "bar"
40+
ostruct.method_26 = "baz"
41+
ostruct.method_27 = "quux"
42+
ostruct.method_28 = "quux"
43+
ostruct.method_29 = "quux"
44+
ostruct.method_0
45+
ostruct.method_1
46+
ostruct.method_2
47+
ostruct.method_3
48+
ostruct.method_4
49+
ostruct.method_5
50+
ostruct.method_6
51+
ostruct.method_7
52+
ostruct.method_8
53+
ostruct.method_9
54+
ostruct.method_10
55+
ostruct.method_11
56+
ostruct.method_12
57+
ostruct.method_13
58+
ostruct.method_14
59+
ostruct.method_15
60+
ostruct.method_16
61+
ostruct.method_17
62+
ostruct.method_18
63+
ostruct.method_19
64+
ostruct.method_20
65+
ostruct.method_21
66+
ostruct.method_22
67+
ostruct.method_23
68+
ostruct.method_24
69+
ostruct.method_25
70+
ostruct.method_26
71+
ostruct.method_27
72+
ostruct.method_28
73+
ostruct.method_29
74+
75+
index_write_attr_read: |
76+
ostruct = OpenStruct.new
77+
keys.each_with_index do ostruct[_1] = _2 end
78+
keys.each do ostruct.send(_1) end
79+
80+
index_write_attr_read: |
81+
ostruct = OpenStruct.new
82+
keys.each_with_index do ostruct[_1] = _2 end
83+
keys.each do ostruct.send(_1) end
84+
85+
null_reads: |
86+
ostruct = OpenStruct.new
87+
ostruct.method_0
88+
ostruct.method_1
89+
ostruct.method_2
90+
ostruct.method_3
91+
ostruct.method_4
92+
ostruct.method_5
93+
ostruct.method_6
94+
ostruct.method_7
95+
ostruct.method_8
96+
ostruct.method_9
97+
ostruct.method_10
98+
ostruct.method_11
99+
ostruct.method_12
100+
ostruct.method_13
101+
ostruct.method_14
102+
ostruct.method_15
103+
ostruct.method_16
104+
ostruct.method_17
105+
ostruct.method_18
106+
ostruct.method_19
107+
ostruct.method_20
108+
ostruct.method_21
109+
ostruct.method_22
110+
ostruct.method_23
111+
ostruct.method_24
112+
ostruct.method_25
113+
ostruct.method_26
114+
ostruct.method_27
115+
ostruct.method_28
116+
ostruct.method_29
117+
118+
10x_reads: |
119+
ostruct = OpenStruct.new(input)
120+
10.times do
121+
ostruct.method_0
122+
ostruct.method_1
123+
ostruct.method_2
124+
ostruct.method_3
125+
ostruct.method_4
126+
ostruct.method_5
127+
ostruct.method_6
128+
ostruct.method_7
129+
ostruct.method_8
130+
ostruct.method_9
131+
end
132+
133+
100x_reads: |
134+
ostruct = OpenStruct.new(input)
135+
100.times do
136+
ostruct.method_0
137+
ostruct.method_1
138+
ostruct.method_2
139+
ostruct.method_3
140+
ostruct.method_4
141+
ostruct.method_5
142+
ostruct.method_6
143+
ostruct.method_7
144+
ostruct.method_8
145+
ostruct.method_9
146+
end
147+
148+
contexts:
149+
- name: v0.6.0
150+
gems:
151+
ostruct: 0.6.0
152+
- name: local
153+
prelude: |
154+
$LOAD_PATH.unshift "./lib"

0 commit comments

Comments
 (0)