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:
send(test_name)
in the report
block. I want to continue seeing this output.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 the Benchmark::Report
object sent to the block by Benchmark.bm
or Benchmark.benchmark
, it will print to STDOUT. If you're just interested in the benchmark metrics without printing a report, you can do this:
benchmark_result = Benchmark.measure do
send(test_name)
end
It returns a Benchmark::Tms
object that looks like this:
=> #<Benchmark::Tms:0x007fb5b1b40118
@cstime=0.0,
@cutime=0.0,
@label="",
@real=4.5693013817071915e-05,
@stime=0.0,
@total=0.0,
@utime=0.0>
If you're just interested in the elapsed real time used to execute your block, do the following (returns a Float
):
benchmark_result = Benchmark.realtime do
send(test_name)
end