I have a benchmark like follows:
benchmark_result = Benchmark.bm do |x|
x.report { send(test_name) }
end
When I run this, I'm seeing output from two places:
- The
send(test_name)
in thereport
block. I want to continue seeing this output. - The output from the Benchmark block, i.e. the resulting benchmark report is printed to the console. I don't want this to happen.
I've seen from here how to temporarily hide the console output. But the problem is that I want the inner block to continue printing its output. I just don't want to see the benchmark results.
When you call the
report
method on theBenchmark::Report
object sent to the block byBenchmark.bm
orBenchmark.benchmark
, it will print to STDOUT. If you're just interested in the benchmark metrics without printing a report, you can do this:It returns a
Benchmark::Tms
object that looks like this:If you're just interested in the elapsed real time used to execute your block, do the following (returns a
Float
):I've accepted Amit's answer because it seems canonical, but I did figure out another way to do it in the meantime.
From this question I have added the following code (slightly modified to include the
touch/rm
calls on thenull.txt
file):With this, I can accomplish my goal using the following:
Although after seeing a better way to do it, this seems very hacky.