Answer the question
In order to leave comments, you need to log in
What is the best way to process stdin in Ruby?
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
Answer the question
In order to leave comments, you need to log in
If you read through a once allocated buffer, then everything flies and the memory does not eat ..
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)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question