-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_bench.rb
48 lines (35 loc) · 873 Bytes
/
create_bench.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
# frozen_string_literal: true
return unless defined?(Data.define)
require_relative '../../lib/ruby-on-speed'
RubyOnSpeed.benchmark 'Struct:create - create a Struct/Data/Hash' do
test_with { _1.to_h == { a: 1, b: 2, c: 3, d: 4 } }
sample = Struct.new(:a, :b, :c, :d)
data_sample = Data.define(:a, :b, :c, :d)
code 'Struct.new' do
sample.new(1, 2, 3, 4)
end
code 'Struct.new(**)' do
sample.new(a: 1, b: 2, c: 3, d: 4)
end
code 'Struct[]' do
sample[1, 2, 3, 4]
end
code 'Struct[**]' do
sample[a: 1, b: 2, c: 3, d: 4]
end
code 'Data.new' do
data_sample.new(1, 2, 3, 4)
end
code 'Data.new(**)' do
data_sample.new(a: 1, b: 2, c: 3, d: 4)
end
code 'Data[]' do
data_sample[1, 2, 3, 4]
end
code 'Data[**]' do
data_sample[1, 2, 3, 4]
end
code 'Hash.new' do
{ a: 1, b: 2, c: 3, d: 4 }
end
end