I'm trying to compare the touch method that Rake includes to shelling out to the system touch.
Each operation is sending output to stdout:
require 'benchmark'
require 'rake'
n = 3
result = Benchmark.bm do |x|
x.report("sh:") do
n.times { sh "touch foo.txt" }
end
x.report("touch:") do
n.times { touch "bar.txt" }
end
end
result:
user system total real
sh:touch foo.txt
touch foo.txt
touch foo.txt
0.000000 0.010000 0.030000 ( 0.024775)
touch:touch bar.txt
touch bar.txt
touch bar.txt
0.000000 0.000000 0.000000 ( 0.000412)
What I'd like is:
user system total real
sh:touch foo.txt
0.000000 0.010000 0.030000 ( 0.024775)
touch:touch bar.txt
0.000000 0.000000 0.000000 ( 0.000412)
Or something else that only has the results.
I read in another question to use Benchmark.measure
but the following also doesn't work:
require 'benchmark'
require 'rake'
n = 3
result = Benchmark.measure do
n.times { sh "touch foo.txt" }
end
puts result
result:
touch foo.txt
touch foo.txt
touch foo.txt
0.000000 0.000000 0.010000 ( 0.022931)
How do I benchmark sh
and touch
but prevent output from going to stdout?