Skip to content

Instantly share code, notes, and snippets.

@aks
Created June 27, 2023 00:07
Show Gist options
  • Save aks/a4cc7eb217c7798f1132f5299e175a88 to your computer and use it in GitHub Desktop.
Save aks/a4cc7eb217c7798f1132f5299e175a88 to your computer and use it in GitHub Desktop.
ActiveRecord memory size usage (minimal and all)
#!/usr/bin/env ruby
require 'get_process_mem'
def mem_usage(label)
Process.fork do
m_before = mem_size
yield
m_after = mem_size
$stderr.printf "%30s: delta: %+3d MB total: %5d MB\n", label, (m_after - m_before), m_after
end
end
def mem_size(digits=0)
@mem ||= GetProcessMem.new
@mem.mb.round(0)
end
mem_usage('Require active_support') { require 'active_support' }
mem_usage('Require active_support/all') { require 'active_support/all' }
$stderr.flush
exit
Require active_support: delta: +12 MB total: 14 MB
Require active_support/all: delta: +24 MB total: 25 MB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment