Hello, I’ve posted a couple of issues and a pull request on the Github benchmark
repo, Is that the right place to post them? Should they be discussed here as well? They are:
opened 12:53AM - 30 Jan 21 UTC
closed 04:03AM - 08 Feb 21 UTC
invalid
`Benchmark::Tms` contains a `to_a` method, but a `to_h` method would also be use… ful. I added a `to_h` method, and a test for it.
When running the test, I found that the test was loading the benchmark code from the Ruby runtime (using `require benchmark`), so my code changes were ignored. The PR for this issue addresses this by using `require_relative` instead.
opened 03:18AM - 30 Jan 21 UTC
closed 12:25AM - 02 Mar 21 UTC
For methods that print to standard output (`benchmark`, `bm`, and `bmbm`), it wo… uld be nice to be able to specify that they go to another stream instead, such as an open file or a string buffer (`StringIO`), or even `$stdout`, in case it has been changed to something other than `STDOUT`.
In cases where the method signature would not support another parameter, an alternate method could be added in which the stream is a parameter, the body of the original method moved there, and the original method remaining to call the new method with `STDOUT`, e.g.:
```
def benchmark(caption = "", label_width = nil, format = nil, *labels)
...
end
```
...could become...
```
def benchmark_to(output_stream, caption = "", label_width = nil, format = nil, *labels)
# body of original benchmark method
end
```
...and...
```
def benchmark(caption = "", label_width = nil, format = nil, *labels)
benchmark_to(STDOUT, caption, label_width, format, *labels)
end
```
I believe all the likely objects for output would support `puts`, `print`, etc. I'm not sure about `sync`, but I suppose we could put a `respond_to?` guard around that call.
ruby:master
← keithrbennett:add_to_h
opened 12:58AM - 30 Jan 21 UTC
Adds a `to_h` method to Benchmark::Tms.
Fixes the test file's `require` to lo… ad the code in the modified benchmark.rb instead of the Ruby distribution.
1 Like