Module: Bench
- Defined in:
- lib/bench.rb
Class Attribute Summary collapse
-
.queue ⇒ Object
readonly
Returns the value of attribute queue.
Class Method Summary collapse
-
.benchmark(name, &block) ⇒ Object
Create a new benchmark sample
name
. -
.run(count = 1) ⇒ Object
Runs the benchmarks.
Class Attribute Details
.queue ⇒ Object (readonly)
Returns the value of attribute queue.
31 32 33 |
# File 'lib/bench.rb', line 31 def queue @queue end |
Class Method Details
.benchmark(name, &block) ⇒ Object
Create a new benchmark sample name
. Within the block you specify the code to execute.
8 9 10 11 12 13 |
# File 'lib/bench.rb', line 8 def benchmark name, &block bm = OpenStruct.new bm.name = name bm.proc = block Bench.queue << bm end |
.run(count = 1) ⇒ Object
Runs the benchmarks. Parameter count
is the number of iterations each sample code should be repeated.
17 18 19 20 21 22 23 24 |
# File 'lib/bench.rb', line 17 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 |