forked from austinthecoder/ivo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmarks.rb
executable file
·81 lines (66 loc) · 1.37 KB
/
benchmarks.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
#!/usr/bin/env ruby
require 'bundler/inline'
require 'benchmark'
require 'ostruct'
gemfile do
source 'https://rubygems.org'
gem 'ivo', '~> 0.4'
gem 'immutable-struct', '~> 2.4'
gem 'values', '~> 1.8'
gem 'concurrent-ruby', '~> 1.1'
end
StructClass = Struct.new(:x, :y)
ImmutableStructClass = ImmutableStruct.new(:x, :y)
ValueClass = Value.new(:x, :y)
IvoClass = Ivo.new(:x, :y)
ConcurrentImmutableStruct = Concurrent::ImmutableStruct.new(:x, :y)
n = 1_000_000
Benchmark.bm(30) do |x|
x.report('StructClass.new') do
n.times do
StructClass.new(1, 2)
end
end
x.report('IvoClass.new') do
n.times do
IvoClass.new(1, 2)
end
end
x.report('IvoClass.with') do
n.times do
IvoClass.with(x: 1, y: 2)
end
end
x.report('ConcurrentImmutableStruct.new') do
n.times do
ConcurrentImmutableStruct.new(1, 2)
end
end
x.report('ValueClass.new') do
n.times do
ValueClass.new(1, 2)
end
end
x.report('ValueClass.with') do
n.times do
ValueClass.with(x: 1, y: 2)
end
end
x.report('ImmutableStructClass.new') do
n.times do
ImmutableStructClass.new(x: 1, y: 2)
end
end
end
Benchmark.bm(30) do |x|
x.report('OpenStruct.new') do
n.times do
OpenStruct.new(x: 1, y: 2)
end
end
x.report('Ivo.call') do
n.times do
Ivo.call(x: 1, y: 2)
end
end
end