Skip to content

Commit 251a4db

Browse files
committed
Add benchmark script
1 parent 7084d83 commit 251a4db

File tree

5 files changed

+60
-0
lines changed

5 files changed

+60
-0
lines changed

Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ gem "rubocop-rubycw"
1313
gem "json"
1414
gem "json-schema"
1515
gem 'stackprof'
16+
gem 'memory_profiler'
1617
gem "goodcheck"
1718
gem "dbm"
1819
gem 'digest'

Gemfile.lock

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ GEM
3333
addressable (>= 2.8)
3434
language_server-protocol (3.17.0.3)
3535
marcel (1.0.2)
36+
memory_profiler (1.0.1)
3637
minitest (5.22.3)
3738
mutex_m (0.2.0)
3839
net-protocol (0.2.2)
@@ -110,6 +111,7 @@ DEPENDENCIES
110111
goodcheck
111112
json
112113
json-schema
114+
memory_profiler
113115
minitest
114116
mutex_m
115117
net-smtp

benchmark/memory_new_env.rb

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require_relative './utils'
2+
3+
require 'memory_profiler'
4+
5+
env = nil
6+
7+
r = MemoryProfiler.report do
8+
env = new_env
9+
end
10+
11+
r.pretty_print

benchmark/memory_new_rails_env.rb

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require_relative './utils'
2+
3+
tmpdir = prepare_collection!
4+
5+
require 'memory_profiler'
6+
7+
env = nil
8+
9+
r = MemoryProfiler.report do
10+
env = new_rails_env(tmpdir)
11+
end
12+
13+
r.pretty_print

benchmark/utils.rb

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
require "rbs"
2+
require 'tmpdir'
3+
4+
def prepare_collection!
5+
tmpdir = Pathname(Dir.mktmpdir)
6+
at_exit { tmpdir.rmtree }
7+
8+
tmpdir.join('Gemfile').write(<<~RUBY)
9+
source "https://rubygems.org"
10+
gem 'rails'
11+
RUBY
12+
Bundler.with_original_env do
13+
system('bundle', 'lock', chdir: tmpdir.to_s)
14+
system('rbs', 'collection', 'init', chdir: tmpdir.to_s)
15+
system('rbs', 'collection', 'install', chdir: tmpdir.to_s)
16+
end
17+
18+
tmpdir
19+
end
20+
21+
def new_env
22+
loader = RBS::EnvironmentLoader.new()
23+
yield loader if block_given?
24+
RBS::Environment.from_loader(loader).resolve_type_names
25+
end
26+
27+
def new_rails_env(collection_dir)
28+
new_env do |loader|
29+
lock_path = collection_dir.join('rbs_collection.lock.yaml')
30+
lock = RBS::Collection::Config::Lockfile.from_lockfile(lockfile_path: lock_path, data: YAML.load_file(lock_path.to_s))
31+
loader.add_collection(lock)
32+
end
33+
end

0 commit comments

Comments
 (0)