Skip to content

Instantly share code, notes, and snippets.

@aks
Created June 27, 2023 00:07
Show Gist options
  • Select an option

  • Save aks/a4cc7eb217c7798f1132f5299e175a88 to your computer and use it in GitHub Desktop.

Select an option

Save aks/a4cc7eb217c7798f1132f5299e175a88 to your computer and use it in GitHub Desktop.

Revisions

  1. aks created this gist Jun 27, 2023.
    23 changes: 23 additions & 0 deletions ar-mem-size.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    #!/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
    2 changes: 2 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    Require active_support: delta: +12 MB total: 14 MB
    Require active_support/all: delta: +24 MB total: 25 MB