You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But often I want to use those numbers somewhere else, e.g. plotting a graph, and to avoid parsing the above table again, I take the returned Benchmark::IPS::Job (the docs don't really mention this) and post-process the items into a JSON:
ips =Benchmark.ips { ... }
j =JSON.build do |json|
json.object do
json.field "items"do
json.array do
ips.items.each do |item|
json.object do
json.field "label", item.label
json.field "mean", item.mean
json.field "stddev", item.stddev
json.field "bytes_per_op", item.bytes_per_op
endendendendendend
IMO this is still not straightforward enough, because I don't want to pollute STDOUT at all. It would be nice if Benchmark.ips itself supports those alternative formats out of the box. So I suggest implementing any of the following:
Add a boolean parameter to suppress the interactive and final printing of results in Benchmark::IPS::Job#execute and #report, respectively.
Allow passing an IO to Benchmark.ips and perform all the printing on that IO. Then one can pass File.open(File::NULL, "w") or a custom no-op IO to suppress the output.
Create some kind of reporter interface and delegate printing to that. Something like:
Benchmark.ips
always prints its result toSTDOUT
in a nicely formatted table:But often I want to use those numbers somewhere else, e.g. plotting a graph, and to avoid parsing the above table again, I take the returned
Benchmark::IPS::Job
(the docs don't really mention this) and post-process the items into a JSON:IMO this is still not straightforward enough, because I don't want to pollute
STDOUT
at all. It would be nice ifBenchmark.ips
itself supports those alternative formats out of the box. So I suggest implementing any of the following:Benchmark::IPS::Job#execute
and#report
, respectively.IO
toBenchmark.ips
and perform all the printing on thatIO
. Then one can passFile.open(File::NULL, "w")
or a custom no-opIO
to suppress the output.TableReporter
andMyJsonReporter
are both testable in isolation, without needing to mock a full benchmark run.Similar points probably hold for
Benchmark.bm
as well.The text was updated successfully, but these errors were encountered: