elasticsearch-ruby

https://github.com/elastic/elasticsearch-ruby

Ruby

Ruby integrations for Elasticsearch

Benchmark.benchmark

Invokes the block with a Benchmark::Report object, which
may be used to collect and report on the results of individual
benchmark tests. Reserves +label_width+ leading spaces for
labels on each line. Prints +caption+ at the top of the
report, and uses +format+ to format each line.
Returns an array of Benchmark::Tms objects.

If the block returns an array of
Benchmark::Tms objects, these will be used to format
additional lines of output. If +label+ parameters are
given, these are used to label these extra lines.

_Note_: Other methods provide a simpler interface to this one, and are
suitable for nearly all benchmarking requirements.  See the examples in
Benchmark, and the #bm and #bmbm methods.

Example:

    require 'benchmark'
    include Benchmark          # we need the CAPTION and FORMAT constants

    n = 5000000
    Benchmark.benchmark(CAPTION, 7, FORMAT, ">total:", ">avg:") do |x|
      tf = x.report("for:")   { for i in 1..n; a = "1"; end }
      tt = x.report("times:") { n.times do   ; a = "1"; end }
      tu = x.report("upto:")  { 1.upto(n) do ; a = "1"; end }
      [tf+tt+tu, (tf+tt+tu)/3]
    end

Generates:

                    user     system      total        real
      for:      0.970000   0.000000   0.970000 (  0.970493)
      times:    0.990000   0.000000   0.990000 (  0.989542)
      upto:     0.970000   0.000000   0.970000 (  0.972854)
      >total:   2.930000   0.000000   2.930000 (  2.932889)
      >avg:     0.976667   0.000000   0.976667 (  0.977630)

Source | Google | Stack overflow

Edit

git clone [email protected]:elastic/elasticsearch-ruby.git

cd elasticsearch-ruby

open

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-Benchmark-benchmark-for-pr


# Commit to git

git add git commit -m "better docs for Benchmark.benchmark"


# Open pull request

gem install hub # on a mac you can `brew install hub`

hub fork

git push <your name> -your-name--update-docs-Benchmark-benchmark-for-pr

hub pull-request


# Celebrate!