Skip to content

Commit c3a6317

Browse files
committed
bench: add benchmark ips for mesuring performance
1 parent b707a47 commit c3a6317

3 files changed

Lines changed: 70 additions & 0 deletions

File tree

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ gem "rubocop", "~> 1.21"
1616
gem "rubocop-config-crystal", "~> 0.0.2"
1717

1818
gem "rubocop-rspec", require: false
19+
20+
gem "benchmark-ips"

Gemfile.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ GEM
77
remote: https://rubygems.org/
88
specs:
99
ast (2.4.3)
10+
benchmark-ips (2.14.0)
1011
diff-lcs (1.6.2)
1112
json (2.15.2)
1213
language_server-protocol (3.17.0.5)
@@ -60,6 +61,7 @@ PLATFORMS
6061
x86_64-linux
6162

6263
DEPENDENCIES
64+
benchmark-ips
6365
bundler (~> 2.4)
6466
rake (~> 13.0)
6567
rs-result!

bench.rb

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# frozen_string_literal: true
2+
3+
require "benchmark/ips"
4+
require_relative "lib/rs/types"
5+
6+
n = 1000
7+
8+
Benchmark.ips do |x|
9+
x.config(warmup: 2, time: 1)
10+
11+
x.report("Some[]") do
12+
n.times do
13+
Some[Integer] { 0 }
14+
end
15+
end
16+
17+
x.report("Some.new") do
18+
n.times do
19+
Some.new(0)
20+
end
21+
end
22+
23+
x.report("None[]") do
24+
n.times do
25+
None[Integer]
26+
end
27+
end
28+
29+
x.report("None.new") do
30+
n.times do
31+
None.new
32+
end
33+
end
34+
35+
x.compare!
36+
end
37+
38+
Benchmark.ips do |x|
39+
x.config(warmup: 2, time: 1)
40+
41+
x.report("Ok[]") do
42+
n.times do
43+
Ok[Integer, Integer] { 0 }
44+
end
45+
end
46+
47+
x.report("Ok.new") do
48+
n.times do
49+
Ok.new(0)
50+
end
51+
end
52+
53+
x.report("Err[]") do
54+
n.times do
55+
Err[Integer, Integer] { 0 }
56+
end
57+
end
58+
59+
x.report("Err.new") do
60+
n.times do
61+
Err.new(0)
62+
end
63+
end
64+
65+
x.compare!
66+
end

0 commit comments

Comments
 (0)