require "memory_profiler"
report = MemoryProfiler.report do
$stdout.sync = true
ARGF.each_char do |c|
$stdout.print(c)
end
end
report.pretty_print(to_file: 'memory_profiler.log')
dd if=/dev/zero bs=1M count=1 | ruby test_stream.rb | wc -c
ARGF.each_char
require "memory_profiler"
report = MemoryProfiler.report do
$stdout.sync = true
buffer_size = 5_000
buffer = String.new("", capacity: buffer_size)
while (readed = $stdin.read(buffer_size, buffer))
$stdout << readed
end
end
report.pretty_print(to_file: "memory_profiler.log")
Total allocated: 5545 bytes (4 objects)
Total retained: 5041 bytes (1 objects)