Skip to content

Instantly share code, notes, and snippets.

@benoittgt
Last active October 26, 2020 17:26
Show Gist options
  • Select an option

  • Save benoittgt/c579b614652b3cebdaada56c76c78d2b to your computer and use it in GitHub Desktop.

Select an option

Save benoittgt/c579b614652b3cebdaada56c76c78d2b to your computer and use it in GitHub Desktop.
# With get process mem Gem from Richard
class MemoryDiff
class << self
def print_usage_before_and_after(description)
mem = GetProcessMem.new.mb
puts "MEM:BEFORE:#{description.inspect} - MEMORY USAGE(MB): #{mem.round(2)}mb"
yield
after_mem = GetProcessMem.new.mb
puts "MEM:AFTER:#{description.inspect} - MEMORY USAGE(MB): #{after_mem.round(2)}mb. Diff: #{display_diff(after_mem - mem)}"
end
private
def display_diff(sum)
if sum.positive?
"⬆ +#{sum.round(2)}mb"
elsif sum.negative?
"⬇ #{sum.round(2)}mb"
else
"NO DIFF"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment