Created
June 11, 2023 23:01
-
-
Save DimaSamodurov/3ab124a6d30f24c6de314b691d5c9e21 to your computer and use it in GitHub Desktop.
measuring Ruby GC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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