Trans <transfire / gmail.com> wrote:
> What is the underlying translation of benchmark? I.e. the original
> Benchmark library has a few different methods, which did you use? I like
> the simplicity of your DSL. In the long run it might be nice to see this
> advance beyond a dependency on the original benchmark library.
Let's look at the code:

  def run count=1
    size = Bench.queue.inject(0) {|max, bm| size = bm.name.size; size > 
max ? size : max}
    Benchmark.bm(size) do |x|
      Bench.queue.each do |bm|
        x.report(bm.name) { count.times {bm.proc.call} }
      end
    end
  end


Two methods of the original benchmark are called:
* Benchmark.bm with an automatic calculated label_width (I don't want to 
think about that).
* Benchmark::Report#report

You can call run as often as you want and do GC.start or whatever before, 
so you can simulate the Benchmark.bmbm method. That is enough for my 
needs.

Maybe there is a better approach? Feel free to contribute:
http://gitorious.org/projects/bench :)

Regards
Jan Friedrich