Skip to content

Instantly share code, notes, and snippets.

@DimaSamodurov
Created June 11, 2023 23:01
Show Gist options
  • Save DimaSamodurov/3ab124a6d30f24c6de314b691d5c9e21 to your computer and use it in GitHub Desktop.
Save DimaSamodurov/3ab124a6d30f24c6de314b691d5c9e21 to your computer and use it in GitHub Desktop.
measuring Ruby GC
require 'benchmark'
def show_memory_consumption
puts `pmap #{Process.pid} | tail -n 1`
end
#GC.disable
result = Benchmark.measure do
200.times { |i|
"a"*100_000_000
#GC.start if i%20 == 0
}
end
puts result
show_memory_consumption
GC.start
show_memory_consumption
pp GC.stat
# Run once, notice execution time, memory consumption and count of GC calls.
# Uncomment lines 7 and 11, run again, notice differences.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment