@ledsun blog

無味の味は佳境に入らざればすなわち知れず

メモリ使用量計測用のRubyスクリプト

とある関数をチューニングしています。 処理時間計測用のRubyスクリプト - @ledsun blogを作って計測しています。 一向に速くなりません。

メモリ使用量を計測することにしました。 次のスクリプトを作りました。

require 'memory_profiler'

file = 'tmp/upload-test-project-2022-06-24-15-05-36/db/litcovid/litcovid2pubtator-2020-11-17-17-47/PMC-7646410.json'
annotations_collection = JSON.parse File.read(file)
annotations_collection.each { _1.deep_symbolize_keys! }
project = Project.find_by(id: 1)

report = MemoryProfiler.report(top: 3) do
  InstantiateAndSaveAnnotationsCollection.call project, annotations_collection
end
report.pretty_print

GitHub - SamSaffron/memory_profiler: memory_profiler for rubyを使いました。 Railsで使っている関数なので、rails runnerから起動しています。

参考