How much Memory does my Ruby Script use ?

I could not find any in-ruby solution for this question, so here is a unix-solution.

def memory
  pid = Process.pid
  map = `pmap -d #{pid}`
  map.split("\n").last
end

Output

mapped: 17652K    writeable/private: 2180K    shared: 0K

Lesson learned
Use `open(file).each(seperator)` over `open(file).read.split(seperator)` if you want to optimize for memory (is slightly slower)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s